当数据集具有不同矢量长度时的 FFT

发布于 2024-12-07 15:33:20 字数 335 浏览 1 评论 0原文

我有来自正在运行的模型的数据。然而,数据是在每个时间步收集的,并且时间步的数量不同。结果表明,尽管时间步长不同,但它可以通过时间步长的变化进行补偿,以便所有运行都在同一时间运行。

然而,我认为当我有一个长度为 200 的向量和一个长度为 900 的向量时,采用 FFT 会给出本质上不同的频率。我觉得我应该对所有样本的同一时间轴进行 FFT。

我现在获取数据的方式就像行向量一样,每个条目不与时间空间关联。

有没有办法获取每个向量相对于它们在时间轴中的位置而不是它们在向量数组中的位置的 fft ?

我的目标是编写一个 for 循环并获取许多数据集的 fft,然后绘制它们以比较频率特征变化。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云胡 2024-12-14 15:33:20

如果您在 1 秒 (200 Hz) 内收集 200 个样本,则可以解析从 1 Hz(1/(1 秒))到 100 Hz 的输入数据。如果采样 1 秒收集 900 个样本,则可以解析从 1 Hz 到 450 Hz 的输入。因此,您的两个样本具有相同的间距(频率轴上的采样为 1 Hz),但它们的最大频率不同!

如果您的问题只是关于绘图,您可以丢弃所有绘图中不可用的高频:

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

...或者接受现实,并绘制您拥有的所有数据:

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

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
℉服软 2024-12-14 15:33:20

您可以将数据(通过过滤插值)重新采样为恒定长度向量,其中每帧中的采样率都是相同的恒定速率。您可能还必须重叠 FFT 帧才能获得恒定的帧或窗口偏移。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文