MATLAB: How to get Magnitude Spectrum of a Cosine Wave

fftwave

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…

Best Answer

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!
Related Question