fft, problem in determining sampling frequency
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Does Matlab have a default sampling frequency for fft function? how can I change it? I mean when i use
A = abs(fft(thesignal));
plot(A);
the x-label is time!! what does it mean? I also tried determining the frequency and then plotting A by the frequency that I-myself- determined that. it works, but it doesn't make sense. because I can change the frequency axis's magnitudes! and the y axis (Amplitude spectrum) is constant... so for a same frequency on the x axis, I'll give different amplitude!! Thanks for reading...
0 comentarios
Respuestas (2)
Wayne King
el 19 de Feb. de 2013
Azzi is correct in his characterization of the default x-axis. The values that you are getting with your code:
A = abs(fft(thesignal));
plot(A);
Are magnitudes associated with frequencies of the form (2*pi*k)/N radians/sample (or k/N cycles/sample) where N is the length of the input signal, and k = 0,1,2,...N-1
Note that the first value is associated with k=0 which corresponds to a frequency of 0 radians/sample, or DC.
Also, keep in mind that discrete frequencies only increase in oscillation up to a point, and then actually start to decrease.
For an even length, N, at k=N/2, the radian frequency is pi radians/sample. Clearly this has a period of 2 samples.
However at k = 3N/4 (provided that is an integer), the radian frequency is 3pi/2 radians/sample and that has a period of 4 samples.
For a real-valued signal, you can choose to plot the output of fft() (the DFT) for only 1/2 the values so you can obtain an easier to interpret plot where the frequency actually increases monotonically.
You can also use fftshift, if you prefer to visualize 0 frequency at the center of the output.
Ex:
n = 0:159;
x = cos(pi/4*n); % pi/4 radians/sample
xdft = fft(x);
N = length(x)
k = 0:N-1;
plot(k,abs(xdft))
Note that peaks at k=20 and k=140 (which is N-k). k=20 is equal to a radian/frequency of (2*pi*k)/N or pi/4 radians/sample (1 cycle/8 samples)
0 comentarios
Azzi Abdelmalek
el 19 de Feb. de 2013
Editada: Azzi Abdelmalek
el 19 de Feb. de 2013
There is no default sampling frequency for fft function. You provide your samples without specifying your sample time, and fft function calculate the discrete Fourier transform of your discrete signal.
in plot(A) there is no x-axis specified. Then by default the x-axis is 1:numel(A), which does not represent neither time, neither frequency. It's just indices
You have to calculate your frequencies data from the sample time of your data a
1 comentario
Azzi Abdelmalek
el 20 de Feb. de 2013
Editada: Azzi Abdelmalek
el 20 de Feb. de 2013
[wc,w0,a0,ak,bk,c0,ck]=get_harmonics(y,pas)
stem(wc,abs(ck))
%y: your signal
% pas your sample time
%The result wc is in rad/s
Ver también
Categorías
Más información sobre Discrete Fourier and Cosine Transforms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!