How to get Magnitude Spectrum of a Cosine Wave

11 次查看(过去 30 天)
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...

采纳的回答

Salaheddin Hosseinzadeh
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!

更多回答(2 个)

Salaheddin Hosseinzadeh
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

Lizy
Lizy 2014-9-9
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

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by