0
votes

I have data from a model I am running. However the data is collected at each time step and there are varying numbers of time steps. It works out that although there are varying time steps, it is compensated by the change in time step so that all runs are running for the same time.

However I would think that when I have a vector that is 200 in length and one that is 900 in length, taking the FFT will give me inherently different frequencies. I feel like I should take the FFT with respect to the same time axis of all the samples.

The way I have the data now is just as row vectors were each entry is not associated with a space in time.

Is there a way to take the fft of each vector with respect to their place in a time axis rather than their place in the vector array?

My goal is to write a for loop and take the fft of many data sets, and then plot them to compare of frequency signatures change.

2

2 Answers

3
votes

If you collect 200 samples in 1 second (200 Hz), you can resolve input data from 1 Hz (1/(1 sec)) to 100 Hz. If you sample for 1 second collecting 900 samples, you can resolve input from 1 Hz to 450 Hz. So both your samples have the same spacing (sampling in the frequency axis is 1 Hz), but they go up to different maximum frequencies!

If your issue is just about plotting, you can either throw away the high frequencies which are not available in all your plots:

totaltime=1; %# common total time of all datasets, in seconds
minsamplenumber=200;
figure;
hold all;
cutofffreq=((minsamplenumber/2+1)/totaltime);
freqscale=0:(1/totaltime):cutofffreq;
datasetcount=42;
ffts=NaN(minsamplenumber,datasetcount);
for i=1:datasetcount
   data{i}=... %# collect your data; to make life easier always collect an even number..
   ffts(:,i)=fft(data{i},minsamplenumber);
   plot(freqscale,ffts{i}(1:end/2+1));
end

... or live with reality, and plot all data you have:

totaltime=1; %# common total time of all datasets, in seconds
figure;
hold all;
for i=1:42
   data{i}=... %# collect your data; to make life easier always collect an even number..
   ffts{i}=fft(data{i});
   maxfreq(i)=((numel(ffts{i})/2+1)/totaltime);
   freqscale{i}=0:(1/totaltime):maxfreq(i);
   plot(freqscale{i},ffts{i}(1:end/2+1));
end
0
votes

You could resample your data (by filtered interpolation) into constant length vectors where the sample rate was the same constant rate in each frame. You may have to overlap your FFT frames as well to get constant frame or window offsets.