+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 20 of 39
  1. #1
    Advanced Member level 1
    Points: 4,947, Level: 16

    Join Date
    May 2004
    Location
    oriental
    Posts
    494
    Helped
    5 / 5
    Points
    4,947
    Level
    16

    matlab spectrum

    Hi all,

    I am a Matlab newbie :)
    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

  2. #2
    Full Member level 5
    Points: 9,373, Level: 23

    Join Date
    Sep 2002
    Posts
    302
    Helped
    22 / 22
    Points
    9,373
    Level
    23

    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


    3 members found this post helpful.

    •   Alt24th December 2005, 09:42

      advertising

        
       

  3. #3
    Full Member level 5
    Points: 3,090, Level: 13

    Join Date
    May 2005
    Posts
    288
    Helped
    4 / 4
    Points
    3,090
    Level
    13

    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?


    1 members found this post helpful.

  4. #4
    Full Member level 5
    Points: 9,373, Level: 23

    Join Date
    Sep 2002
    Posts
    302
    Helped
    22 / 22
    Points
    9,373
    Level
    23

    spectrum matlab

    Hi

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

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

    Regards


    2 members found this post helpful.

  5. #5
    Full Member level 5
    Points: 3,090, Level: 13

    Join Date
    May 2005
    Posts
    288
    Helped
    4 / 4
    Points
    3,090
    Level
    13

    matlab frequency plot

    Circuit_seller wrote:

    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?



  6. #6
    Full Member level 4
    Points: 2,906, Level: 12

    Join Date
    Aug 2005
    Location
    Salvador-BA-Brazil
    Posts
    226
    Helped
    28 / 28
    Points
    2,906
    Level
    12

    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


    2 members found this post helpful.

  7. #7
    Full Member level 5
    Points: 9,373, Level: 23

    Join Date
    Sep 2002
    Posts
    302
    Helped
    22 / 22
    Points
    9,373
    Level
    23

    frequency plot matlab

    Hi

    Sorry,
    f = 0 : Fs / N : Fs - 1 / N;



    •   Alt25th December 2005, 07:44

      advertising

        
       

  8. #8
    Full Member level 5
    Points: 3,089, Level: 13

    Join Date
    Jan 2006
    Posts
    287
    Helped
    19 / 19
    Points
    3,089
    Level
    13

    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..



  9. #9
    Full Member level 5
    Points: 3,090, Level: 13

    Join Date
    May 2005
    Posts
    288
    Helped
    4 / 4
    Points
    3,090
    Level
    13

    plot frequency spectrum matlab

    Hello;
    Circuit_Seller wrote this relation:

    f = 0 : Fs / N : Fs - 1 / N
    Can anyone explain more about this relation? How is the relation resulted?



    •   Alt17th January 2006, 15:21

      advertising

        
       

  10. #10
    Full Member level 5
    Points: 9,373, Level: 23

    Join Date
    Sep 2002
    Posts
    302
    Helped
    22 / 22
    Points
    9,373
    Level
    23

    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



  11. #11
    Member level 2
    Points: 2,213, Level: 10

    Join Date
    Jul 2004
    Posts
    53
    Helped
    7 / 7
    Points
    2,213
    Level
    10

    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);


    6 members found this post helpful.

  12. #12
    Full Member level 1
    Points: 2,111, Level: 10

    Join Date
    Jul 2006
    Posts
    117
    Helped
    8 / 8
    Points
    2,111
    Level
    10

    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



  13. #13
    Junior Member level 1
    Points: 1,592, Level: 9

    Join Date
    Aug 2005
    Posts
    15
    Helped
    6 / 6
    Points
    1,592
    Level
    9

    frequency spectrum in matlab

    Perhaps that tutorial about FFT can help you


    3 members found this post helpful.

  14. #14
    Junior Member level 3
    Points: 1,696, Level: 9

    Join Date
    May 2005
    Posts
    27
    Helped
    0 / 0
    Points
    1,696
    Level
    9

    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.



  15. #15
    Member level 5
    Points: 1,342, Level: 8

    Join Date
    Apr 2007
    Posts
    94
    Helped
    6 / 6
    Points
    1,342
    Level
    8

    matlab spectrum plot

    a=abs(fft

    b=angle(fft)

    plot(a)

    plot(angle(b))



  16. #16
    Newbie level 2
    Points: 984, Level: 7

    Join Date
    Jun 2007
    Posts
    2
    Helped
    0 / 0
    Points
    984
    Level
    7

    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@50 Ohm for sine signal with amplitude 2Vp-p. MatLab shows power 0dB@fc

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



  17. #17
    Junior Member level 3
    Points: 1,715, Level: 9
    cfreng2's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Helped
    10 / 10
    Points
    1,715
    Level
    9

    matlab plot frequency

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



  18. #18
    Full Member level 3
    Points: 1,772, Level: 9

    Join Date
    Aug 2007
    Posts
    157
    Helped
    8 / 8
    Points
    1,772
    Level
    9

    spectral plot matlab

    select fft box from DSp tool box.



  19. #19
    Member level 1
    Points: 1,462, Level: 8

    Join Date
    Aug 2005
    Posts
    39
    Helped
    5 / 5
    Points
    1,462
    Level
    8

    matlab plot frequency spectrum

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

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

    will give you the power spectrum


    1 members found this post helpful.

  20. #20
    Newbie level 2
    Points: 917, Level: 6

    Join Date
    Nov 2007
    Posts
    2
    Helped
    0 / 0
    Points
    917
    Level
    6

    spectrum in matlab

    Quote Originally Posted by davyzhu
    Hi all,

    I am a Matlab newbie :)
    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.



+ Post New Thread
Please login
Page 1 of 2 12 LastLast