简体   繁体   中英

Remap FFT frequency bin distribution in C#

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.

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.

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 eg http://en.wikipedia.org/wiki/Lanczos_resampling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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