electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Matlab, How to get frequency spectrum?


Post new topic  Reply to topic    EDAboard.com Forum Index -> Electronic Elementary Questions -> Matlab, How to get frequency spectrum?
Author Message
davyzhu



Joined: 23 May 2004
Posts: 521
Helped: 3
Location: oriental


Post24 Dec 2005 7:38   

matlab spectrum


Hi all,

I am a Matlab newbie Smile
How to get frequency spectrum of a vector data? (something like [3 4 2 10 ...])

I heard FFT is the time-frequency fransform. And I tried fft() function in Matlab.
But it return a complex number. Is it stand for both frequency and phase?

Any suggestions will be appreciated!
Best regards,
Davy
Back to top
Circuit_seller



Joined: 23 Sep 2002
Posts: 415
Helped: 15


Post24 Dec 2005 10:42   

matlab frequency spectrum


Hi

Yes, the fft results contain both amplitude and phase information.
To plot only the amplitude try abs( fft( ... ) );
Another useful MATLAB function for psd plotting is pwelch.

Regards
Back to top
No one



Joined: 11 May 2005
Posts: 352
Helped: 3


Post24 Dec 2005 11:57   

frequency spectrum matlab


Hello Circuit_Seller;
In fft() you get fft. But if you want to plot it, you need frequency, that is you must write:
plot( f , fft )
How you can get frequency vector?
Back to top
Circuit_seller



Joined: 23 Sep 2002
Posts: 415
Helped: 15


Post24 Dec 2005 12:18   

spectrum matlab


Hi

If N is the FFT length and Fs is sampling frequency then

f = 0 : Fs / N : ( Fs - 1 ) / N;

Regards
Back to top
No one



Joined: 11 May 2005
Posts: 352
Helped: 3


Post24 Dec 2005 13:25   

matlab frequency plot


Circuit_seller wrote:

Quote:
If N is the FFT length and Fs is sampling frequency then

f = 0 : Fs / N : ( Fs - 1 ) / N;

I think that your expression isn't true.

Fs / N > ( Fs - 1 ) / N

Can you explain more? How did you take this result?
Back to top
claudiocamera



Joined: 19 Aug 2005
Posts: 249
Helped: 22
Location: Salvador-BA-Brazil


Post24 Dec 2005 19:51   

plot spectrum matlab


Lets try to help:

In order to plot a simple estimation of the spectrum using fft you must pay attention to some details.

Try to increase resolution using zero padding.
Try to avoid spectral leakage, it is easy when you know the spetrum and are just confirming it using fft.

use the command fftshift it takes the center of the signal to origin. eg Yn=abs(fftshift(fft(y,n)))/N where N is the number of points of the signal and n >N is the number of points of the DFT ( n-N is zero padding).

In order to plot the frequency you do:

Having a DFT with n points the vector of frequency is f=[-n/2: (n-1)/2]*Fs/n using this and the fftshift the values in the plot are directly given in Hertz.

I hope have helped
Back to top
Circuit_seller



Joined: 23 Sep 2002
Posts: 415
Helped: 15


Post25 Dec 2005 8:44   

frequency plot matlab


Hi

Sorry,
f = 0 : Fs / N : Fs - 1 / N;
Back to top
Naveed Alam



Joined: 06 Jan 2006
Posts: 292
Helped: 16


Post06 Jan 2006 19:33   

matlab plot spectrum


type in matlab command window, the following one by one
help plot
help stem
help polar

furthermore, suppose that Z=complex matrix, then
real(Z) , GIVES U ONLY REAL VALVUES,,,
complex values can nicely be plot in polar graph, by plotting:
abs(Z) against angle(Z)...
i think it will help u..
Back to top
No one



Joined: 11 May 2005
Posts: 352
Helped: 3


Post17 Jan 2006 16:21   

plot frequency spectrum matlab


Hello;
Circuit_Seller wrote this relation:

Quote:
f = 0 : Fs / N : Fs - 1 / N


Can anyone explain more about this relation? How is the relation resulted?
Back to top
Google
AdSense
Google Adsense




Post17 Jan 2006 16:21   

Ads




Back to top
Circuit_seller



Joined: 23 Sep 2002
Posts: 415
Helped: 15


Post18 Jan 2006 10:45   

matlab fft spectrum


Hi

When you perform a FFT with length N, [0 Fs] is divided to N frequency bins.
So to produce frequency bins i wrote that expression.

Regards
Back to top
starfish



Joined: 08 Jul 2004
Posts: 73


Post10 Jul 2006 17:39   

fourier spectrum matlab


I am uploading 2 PDF files on Fourier Transform / Spectrum calculation and display in Matlab. I used it for the lab of DSP.

You can also use the below function for displaying the frequency spectrum in MATLAB. As "N" the number of points for fft increases the spectrum becomes more accurate to the theoratical values.

Here 'signal' is the data vector for which u want to see the frequency spectrum. 't' is the time vector for which the signal exists , 'ts' is the sampling time , 'N' is the number of fourier transform points.

function[freq,mag]=fouriertransform(signal,t,ts,N);
S=fft(signal,N);
CS=[S(N/2+1:N) S(1:N/2)];
freq=[-N/2+1:N/2]/(N*ts);
mag=abs(CS);
figure;
plot(freq,mag);



Sorry, but you need login in to view this attachment

Back to top
tronix



Joined: 06 Jul 2006
Posts: 121
Helped: 6


Post10 Jul 2006 18:49   

fft spectrum matlab


Hi
Well fft gives a complex function.
To plot absolute value and d phase type following

plot(abs(fft))
plot(angle(fft))

u can also refer to help files
Back to top
mario82



Joined: 18 Aug 2005
Posts: 15
Helped: 3


Post12 Jul 2006 15:01   

frequency spectrum in matlab


Perhaps that tutorial about FFT can help you


Sorry, but you need login in to view this attachment

Back to top
beargebinjie



Joined: 04 May 2005
Posts: 35


Post12 Sep 2006 10:11   

phase spectrum matlab


This is my understanding about DFT. DFT builds the relationship between the samples of signal x(t) and the samples of its FT X(f).
time-domain sampling interval is T, the sample freq is FS=1/T. and freq domain sample interval is f0, so time domain truncation duration is 1/f0=T0, and both sampling number in the t-domain and f-domain are N=T0/T.
so the t-domain data is x(T*n) ,n=[0:N0-1]. data point in t-domain is 0:T:T*(N0-1).
and x(t)'s discrete fourier tranform is fft(T*x(T*n)). and the freq point is 0:f0:FS.

Added after 1 minutes:

This is my understanding about DFT. DFT builds the relationship between the samples of signal x(t) and the samples of its FT X(f).
time-domain sampling interval is T, the sample freq is FS=1/T. and freq domain sample interval is f0, so time domain truncation duration is 1/f0=T0, and both sampling number in the t-domain and f-domain are N=T0/T.
so the t-domain data is x(T*n) ,n=[0:N0-1]. data point in t-domain is 0:T:T*(N0-1).
and x(t)'s discrete fourier tranform is fft(T*x(T*n)). and the freq point is 0:f0:FS.
Back to top
smith123



Joined: 06 Apr 2007
Posts: 105
Helped: 5


Post20 Aug 2007 11:08   

matlab spectrum plot


a=abs(fft

b=angle(fft)

plot(a)

plot(angle(b))
Back to top
zhenyabb



Joined: 28 Jun 2007
Posts: 2


Post20 Aug 2007 14:04   

matlab fourier spectrum


in MatLab help is good example for fft,

roughly output spectrum in dB is:
20log10(abs(fft(sin(2*pi*fc*tt))))

in this case the amlitude is 2 peak-to-peak that corresponds 10 dBm(at)50 Ohm for sine signal with amplitude 2Vp-p. MatLab shows power 0dB(at)fc

Can somebody say how take into account this 50 Ohm output impedance to get proper power?
Back to top
cfreng2



Joined: 12 Jul 2006
Posts: 112
Helped: 9


Post30 Sep 2007 11:20   

matlab plot frequency


if you want to plot the frequency and phase response of the vector you have, you can use the function freqz....
Back to top
suru



Joined: 31 Aug 2007
Posts: 164
Helped: 4


Post10 Oct 2007 12:07   

spectral plot matlab


select fft box from DSp tool box.
Back to top
ddkrishna



Joined: 09 Aug 2005
Posts: 73
Helped: 4


Post31 Oct 2007 16:38   

matlab plot frequency spectrum


let s be your signal;
N = NFFT
Fs = sampling freq

y = fft(s,N);
p = abs(y);
f=Fs/N.*(0SadN/2)-1);
plot(f,p(1:N/2));

will give you the power spectrum
Back to top
vlsi_iitkgp



Joined: 03 Nov 2007
Posts: 2


Post03 Nov 2007 18:27   

spectrum in matlab


davyzhu wrote:
Hi all,

I am a Matlab newbie Smile
How to get frequency spectrum of a vector data? (something like [3 4 2 10 ...])

I heard FFT is the time-frequency fransform. And I tried fft() function in Matlab.
But it return a complex number. Is it stand for both frequency and phase?

Any suggestions will be appreciated!
Best regards,
Davy


hi,
the solution of this problem is that first find the fft then try the command freqz()
that have the arguments fft result,1,1024.
Back to top
pngzhi



Joined: 20 Jan 2008
Posts: 112
Helped: 7


Post26 Mar 2008 3:43   

plot frequency matlab


Use psd(x) function.
Back to top
shabzbd



Joined: 09 Jul 2008
Posts: 3


Post10 Jul 2008 4:29   

plotting spectrum in matlab


claudiocamera wrote:
eg Yn=abs(fftshift(fft(y,n)))/N where N is the number of points of the signal and n >N is the number of points of the DFT ( n-N is zero padding).


Why are we dividing by N??

If you could please explain.
Back to top
xulfee



Joined: 27 May 2008
Posts: 434
Helped: 32
Location: Pakistan


Post10 Jul 2008 4:49   

how to plot spectrum in matlab


fft is command to see spectrum plot it against frequency
Back to top
shabzbd



Joined: 09 Jul 2008
Posts: 3


Post10 Jul 2008 8:41   

fft matlab spectrum


I understand that FFT is for plotting in the Frequency domain.. but why are we "Dividing by N"??

Added after 1 minutes:

zhenyabb wrote:
in MatLab help is good example for fft,

roughly output spectrum in dB is:
20log10(abs(fft(sin(2*pi*fc*tt))))

in this case the amlitude is 2 peak-to-peak that corresponds 10 dBm(at)50 Ohm for sine signal with amplitude 2Vp-p. MatLab shows power 0dB(at)fc

Can somebody say how take into account this 50 Ohm output impedance to get proper power?



Did anyone get an answer to this.. please??
Back to top
Aya2002



Joined: 12 Dec 2006
Posts: 1409
Helped: 254
Location: Iraq


Post02 Feb 2009 23:42   

signal spectrum matlab


Hi to every body

realy this forum is very good

such discussions are very useful

thanks to all the replyers
Back to top
chanphat01001



Joined: 26 Oct 2009
Posts: 1
Location: VietNam


Post26 Oct 2009 11:30   

Re: Matlab, How to get frequency spectrum?


i think, only need use plot(abs(fft(y)))!
Back to top
tavakoliahmad



Joined: 14 Nov 2009
Posts: 2


Post14 Nov 2009 13:16   

Re: fourier spectrum matlab


starfish wrote:
I am uploading 2 PDF files on Fourier Transform / Spectrum calculation and display in Matlab. I used it for the lab of DSP.

You can also use the below function for displaying the frequency spectrum in MATLAB. As "N" the number of points for fft increases the spectrum becomes more accurate to the theoratical values.

Here 'signal' is the data vector for which u want to see the frequency spectrum. 't' is the time vector for which the signal exists , 'ts' is the sampling time , 'N' is the number of fourier transform points.

function[freq,mag]=fouriertransform(signal,t,ts,N);
S=fft(signal,N);
CS=[S(N/2+1:N) S(1:N/2)];
freq=[-N/2+1:N/2]/(N*ts);
mag=abs(CS);
figure;
plot(freq,mag);


hi,
I want to get FFT from non-stationary wave. I know that I should use data window.
I've wrriten a code for it but I don't know my code is correct or not?
please help me
Back to top
Aya2002



Joined: 12 Dec 2006
Posts: 1409
Helped: 254
Location: Iraq


Post15 Nov 2009 18:42   

Re: fourier spectrum matlab


tavakoliahmad wrote:

hi,
I want to get FFT from non-stationary wave. I know that I should use data window.
I've wrriten a code for it but I don't know my code is correct or not?
please help me


see this post
http://www.edaboard.com/ftopic343334.html

scroll down to see it
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Electronic Elementary Questions -> Matlab, How to get frequency spectrum?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
How to get frequency response of a filter in Matlab? (2)
Frequency Spectrum in Matlab (3)
matlab simulink - sine wave frequency spectrum problem (2)
How to get Low IF spectrum of mixer in Spectre ? (1)
How to get a normalized power spectrum for a PCW? (5)
how to find frequency spectrum from fft function? (1)
how to get a temperature insensitive frequency? (9)
how to get E, H distribution for arbitrary frequency (2)
how can i get frequency response of switch capacitor? (2)
How to get two different frequency signal synchrously? (6)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS