简体   繁体   English

在C#中重新映射FFT频点分布

[英]Remap FFT frequency bin distribution in C#

I've coded up the FFT for a dataset I'm working with. 我已经为正在使用的数据集进行了FFT编码。 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. 例如,将500个值的数组映射到1250个元素长的数组。 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. 我可能还需要走另一条路,比如说将值映射到一个300个元素长的数组。 I'm not a math major and am coming up with a blank on this one. 我不是数学专业的学生,​​因此想出一个空白。

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. 当执行FFT时,它将在填充零后的长度上完成,并为您提供与像素相同数量的输出采样。

When you zero-pad an FFT input, the FFT essentially interpolates in the frequency domain automatically. 当您对FFT输入进行零填充时,FFT实际上会在频域中自动内插。 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. 我不确定采用另一种方法(降采样)的最佳方法,但是我认为这样做的一种方法是仅转换所需的前N个样本。 You would be losing data with this, but it may not matter depending on the application. 这样做可能会丢失数据,但可能并不重要,具体取决于应用程序。

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. 如果要按比例放大,则需要在适当的窗口中使用sinc函数。 See eg http://en.wikipedia.org/wiki/Lanczos_resampling 参见例如http://en.wikipedia.org/wiki/Lanczos_resampling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM