在 C# 中重新映射 FFT 频率仓分布
我已经为我正在使用的数据集编写了 FFT 代码。我的目的是创建结果的瀑布图,但我遇到的问题是,如果我更改输入数据大小,那么我会得到不同数量的频率箱。目前,我只是将输入数据集的大小设置为需要映射到的像素数的两倍。我试图找出一种方法将任何数据集大小的频率箱映射到特定数量的像素。例如,将包含 500 个值的数组映射到长度为 1250 个元素的数组。如果能够选择对数据映射执行线性和非线性插值,那就太好了。我可能还需要采用其他方法,例如将值映射到 300 个元素长的数组。我不是数学专业的,我在这方面出现了空白。
I've coded up the FFT for a dataset I'm working with. My intent is to create a waterfall plot of the result, but the problem I'm running into is if I change my input data size, then I get a different number of frequency bins. Currently I'm just making my input dataset twice the size of the number of pixels I need to map to. I'm trying to figure out a way to map the frequency bins of any data set size to a specific number of pixels. For example, mapping an array of 500 values to an array that is 1250 elements long. It would be nice to have the option to perform linear and non-linear interpolation on the data mapping. I also might need to go the other way, say to map the values to an array that is 300 elements long. I'm not a math major and am coming up with a blank on this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所需要做的就是将您的输入用零填充到您想要显示的像素数。这是通过简单地将零附加到您的输入以使其达到您想要的长度(以像素为单位)来完成的。执行 FFT 时,将以补零后的长度完成,并为您提供与像素相同数量的输出样本。
当您对 FFT 输入进行零填充时,FFT 本质上会自动在频域中进行插值。检查这个。请注意,即使频域样本的数量增加,这实际上并不会为您提供频域中的任何更多信息(使用此方法不会仅仅出现新的频率内容)。这只是对现有数据进行过采样。
我不确定采取另一种方式(下采样)的最佳方法,但我认为一种方法是只转换您需要的前 N 个样本。您可能会因此丢失数据,但这可能并不重要,具体取决于应用程序。
All you need to do is zero-pad your input to the number of pixels you want to display. This is done by simply appending zeros to your input to bring it up to the length you want in pixels. When the FFT is performed, it will be done at the length after zero-padding and give you the same number of output samples as you have pixels.
When you zero-pad an FFT input, the FFT essentially interpolates in the frequency domain automatically. Check this out. Note than this does not actually give you any more information in the frequency domain (new frequency content will not just appear by using this method) even though the number of frequency domain samples is increased. This is just oversampling the existing data.
I'm not sure the best way to go the other way (downsampling), but I assume one way to do so would be to just transform the first N samples that you need. You would be losing data with this, but it may not matter depending on the application.
离散傅里叶变换(无论快慢)始终会为您提供与输入数组相同大小的输出数组。如果你想放大它,那么你需要考虑使用带有合适窗口的 sinc 函数。参见例如 http://en.wikipedia.org/wiki/Lanczos_resampling
A discrete Fourier transform (fast or not) will always give you the same size output array as input array. If you want to scale it up then you need to look at using sinc functions with a suitable window. See e.g. http://en.wikipedia.org/wiki/Lanczos_resampling