Search code examples
matlabfunctionplotfftfrequency-analysis

Fourier Analysis - MATLAB


Good evening guys,

I wanna ask you a question regarding the analysis of a function in the domain of frequencies (Fourier). I have two vectors: one containing 7700 values for pressure, and the other one containing 7700 values (same number) for time.

For example, I call the firt vector "a" and the second one "b". With the command "figure(1),plot(a,b)" I obtain the curve in the domain of time.

How can I do to plot this curve in the domain of frequency, to make Fourier transform?

I've read about the function "fft", but I've not understood very well how it can be used...can anyone help me?

Thanks in advance for your attention!


Solution

  • fft returns spectrum as complex numbers. In order to analyze it you have to use its absolute value or phase. In general, it should look like this (let's assume that t is vector containing time and y is the one with actual signal, N is the number of samples):

    fY = fft(y) / (N/2) % scale it to amplitude, typically by N/2
    amp_fY = abs(fY)
    phs_fY = angle(fY)
    

    Additionally, it would be nice to have FFT with known frequency resolution. For that, you need sampling period/frequency. Let's call that frequency fs:

    fs = 1/(t(1) - t(0))
    

    and the vector of frequencies for FFT (F) should be:

    F = (0:fs/N:(N-1)*fs/N)
    

    and finally plots:

    plot(F, amp_fY)
    % or plot(F, phs_fy) according to what you need
    

    I you can use stem instead of plot to get some other type of chart.

    Note that the DC component (the average value) will be doubled on the plot.

    Hope it helps