[SOLVED] Fourier transform of cosine

Status
Not open for further replies.

Mustaine

Member level 1
Joined
Mar 27, 2021
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
214
Hello friends why matlab gives the magnitude fourier transform of cosine as 250.
is not it should be 1/2 according to the equation below.
thanks
--- Updated ---

this is the matlab code:
Code:
Tsample = 1/50;
t = 0:Tsample:10-Tsample;                     
x = cos(2*pi*10*t);
figure
plot(t,x)
xlabel('Time (seconds)')
ylabel('Amplitude')
y = fft(x); 
fsample = 1/Tsample;
n = length(x);                         
fshift = (-n/2:n/2-1)*(fsample/n);
yshift = fftshift(y);
figure
stem(fshift,abs(yshift))
xlabel('Frequency (Hz)')
ylabel('Magnitude')
--- Updated ---

i tried to do that on simulink by changing the frequency as 1k .
type of the spectrum power and the unit is watts but i get the magnitude as 0.25.
is that value correct
also the magnitude is varied by the sample time why is that
thanks in advance.
 

Attachments

  • pic2.JPG
    9.4 KB · Views: 225
  • pic.JPG
    59.6 KB · Views: 232
  • pic4.JPG
    142.9 KB · Views: 229
  • pic3.JPG
    92.6 KB · Views: 226
Last edited:

Hi,

have look at the MATLAB help function, by entering "help fft" into your command window. There you will find an example how to use fft. It seems you forgot to divide your fft result by the number of samples (here n).

BR
 

Hi,

have look at the MATLAB help function, by entering "help fft" into your command window. There you will find an example how to use fft. It seems you forgot to divide your fft result by the number of samples (here n).

BR
thanks for your reply i actually imitate the code according the matlab website but on the website also magnitudes are very high i.e.(https://www.mathworks.com/help/matlab/math/fourier-transforms.html)
after i divide the magnitude to n it gave me the correct result
could you explain the reason of it
thanks in advance
 

Hi,

it depends on the "implementation" of the FFT, by means using a scaling factor or not. The picture below is from "Uderstanding Digital Signal Processing" by Richard G. Lyons and addresses this issue.



At the modaterators (e.g. @KlausST or @FvM ), I hope it is fine to post the picture of two page of a book (not available on google books). To be hornest it's long time ago I have read and agreed to the board rules. If it is not in agreement with the board rules, please delete the picture above.

BR
 

thanks for the reply i also did not know that there is a issue about N samples i thought i was wrong.
thanks for the book recommendation.
 

thanks for the book recommendation.
I like the mentioned book and I own an "analog" version. I refernced it as I knew Lyon is adressing this topic. If you do not want to spend money, I can recommend [1], which is freely accessable online, and also available in printed form.

[1] https://www.dspguide.com/pdfbook.htm

BR
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…