-1

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!

Firefly
  • 23
  • 6
  • 1
    check this example http://uk.mathworks.com/help/matlab/math/fast-fourier-transform-fft.html – marsei May 10 '15 at 21:06
  • The link by macduf says it all. I would love to write an answer but it would probably take me a very long time to write something meaningful. Instead, take a look at the above link. – rayryeng May 10 '15 at 21:32

1 Answers1

0

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

alagner
  • 3,448
  • 1
  • 13
  • 25
  • Thanks for the help alagner. If I have understood, for samples (in this case) we refer to the number of elements contained in the vectors. For example, if t (vector time) and y contain 7700 values, then N = 7700, am I right? – Firefly May 11 '15 at 15:07
  • Samples are single values of vector y. N is the number of samples, so the answer is yes, it's the size of vector y. – alagner May 11 '15 at 22:37