How to get Magnitude Spectrum of a Cosine Wave
11 views (last 30 days)
Show older comments
Upesh
on 29 Aug 2014
Answered: Salaheddin Hosseinzadeh
on 11 Sep 2014
im trying to get magnitude spectrum of a cosine wave x(t)=cos(2*pi*fo*t),0<t<T; where fo=2000hz and sampling frequency Fs=32kHz.Also,samples need be generated at the rate of Fs over a time interval T. (signal length T has to be chosen such that there are 1024 samples of the simulated analog signal).
im not getting the correct spike...
0 Comments
Accepted Answer
Salaheddin Hosseinzadeh
on 29 Aug 2014
Hi Upsesh,
This can be solved by properly using fft (Fast Fourier Transform)
I wrote a fftplot function wich plots the magnitude and returns the coeffs, I'll attach it here, have a look at it and you'll learn how to use FFT. I'll also attach a PDF file regarding how to use FFT.
Hope this helps.
Good Luck!
More Answers (2)
Salaheddin Hosseinzadeh
on 11 Sep 2014
Hi Lizy,
Please do us a favor
1- edit your code so that we can read it. As it's really hard to follow, make it something like this
sample = 1000;
fs = 500;
2- Why don't you use, the files I attached in my previous answer? (the one above). If you don't like my code at least you can use MATLAB's imbedded fft function which take the Fourier transform of your signal?!
Please try the files provided, in the accepted answer or try fft and if you still had problem let us know.
doc fft
Good Luck
0 Comments
Lizy
on 9 Sep 2014
Hi, I need help to plot magnitude spectrum.. I've tried the following codes but it seems not working.. pls help ... thanks in advance ..
sample= 10000; % contains 10000 points -- sampling frequency f = 500; t = linspace(-f,f,sample+1); % frequency vector -500Hz<= f<500Hz t = t(1:end-1)
figure S2f = exp((-j*4*pi*f)./(2+j*2*pi*f)^2)+((1./200*pi)*(sin(inf)-sin(400*pi))); S2f_mag = abs(S2f); plot(S2f_mag) % plot magnitude spectrum title('Magnitude Spectrum S2(f)') hold on
0 Comments
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!