Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
    pic2.JPG
    9.4 KB · Views: 154
  • pic.JPG
    pic.JPG
    59.6 KB · Views: 159
  • pic4.JPG
    pic4.JPG
    142.9 KB · Views: 147
  • pic3.JPG
    pic3.JPG
    92.6 KB · Views: 148
Last edited:

stenzer

Advanced Member level 3
Joined
Oct 1, 2012
Messages
712
Helped
114
Reputation
229
Reaction score
161
Trophy points
1,323
Activity points
7,532
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
 

Mustaine

Member level 1
Joined
Mar 27, 2021
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
214
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
 

stenzer

Advanced Member level 3
Joined
Oct 1, 2012
Messages
712
Helped
114
Reputation
229
Reaction score
161
Trophy points
1,323
Activity points
7,532
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.

Lyon_DFT.png


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
 

Mustaine

Member level 1
Joined
Mar 27, 2021
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
214
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.

View attachment 169320

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.
 

stenzer

Advanced Member level 3
Joined
Oct 1, 2012
Messages
712
Helped
114
Reputation
229
Reaction score
161
Trophy points
1,323
Activity points
7,532
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top