FFT frequency range/sample frequency simple problem
Mostrar comentarios más antiguos
I'm writing a code to process vibration acceleration time-history data by filtering into 1/3-octave bands, and I need to check that the filtered data is being processed correctly. To do this I would like to compare with a general FFT of the the time-history data. However, when I've tried to code this, I've run into problems getting the Matlab FFT algorithm to do what I want. So I've reverted to processing simple sine waves in an attempt to get a correct answer from that, before going back to the more complex acceleration data.
I've isolated the FFT part of the code, which is based on the example code found in the fft function information. However, my understanding of the finer points of shifting the data and setting the transform length and frequency range is still quite poor.
This is the isolated part of the code as it currently stands:
t = linspace(0,1,1000);
fs = length(t)/(max(t) - min(t));
y = 0.5*sin(2*pi*100*t) + 0.5*sin(2*pi*50*t);
m = length(t); % Window length
tl = pow2(nextpow2(m)); % Transform length
P1fft = fft(y,tl); % DFT
%P2fft = fft(P2,tl); % DFT
f = (0:tl-1)*(fs/tl); % Frequency range
P1ffts = fftshift(P1fft); % Zero-shift periodogram
%P2ffts = fftshift(P2fft); % Zero-shift periodogram
% FFT
figure
% semilogx(f,abs(P2ffts),f,abs(P1ffts))
plot(f(1:floor(tl/2)),abs(P1ffts(1:floor(tl/2))))
grid
% xlim([min(f) max(f)])
% xlim([2.5 100])
% ylim([0 0.014])
% set(gca,'XTick',Fref)
I note that if I set the sample frequency to 300Hz, this gives the correct output, but any other sample frequency does not. Clearly this must be related to the frequency range, but my brain is not able to make what is no doubt a fairly simple connection between these two bits of information, which is due to my lack of understanding of the how the code is running.
I have searched through the FFT threads already existing for some help, but perhaps this problem is so simple most people don't need to ask!
Thanks in advance for any help,
Mike
Categorías
Más información sobre Transforms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!