How nearby? Well, that depends on how good you want it to sound. So at every 4th location (since you're downsampling by a factor of 4) you can add up the points near it, multiplied by sin (a dt) / a dt, where dt is the distance in time to that location. This turns out to be proportional to the "sinc" function (sin at)/at, where a is the width of the box in the frequency space. So, if we want to work in the time domain, we need to perform a convolution with the (inverse) Fourier transform of box function. The (inverse) Fourier transform turns pointwise multiplication into a convolution of the (inverse) Fourier transforms of the functions, and vice-versa. Mathwise, discarding everything outside the low-frequency band is multiplication by a box function in frequency space. Instead you'll want to use a "kernel" function that averages them together in a non-intuitive way. The naïve way of grabbing samples four by four and doing an equal weighted average works, but isn't too great. You can do an adequate job by averaging sample values together. In the first case, you want the middle 1/4th. If it's a complex FFT (which is much easier to analyze, and generally has nicer properties), the frequencies will either go from -22 to 22, or 0 to 44. Be aware of how your FFT package stores samples though. Padding to a power of 2 number of samples will probably give you a speed benefit. Discarding the top 3/4ths is a low-pass filter in this case. The "best" solution possible is indeed a DFT, discarding the top 3/4 of the frequencies, and performing an inverse DFT, with the domain restricted to the bottom 1/4th. Try googling for polyphase IIR or polyphase FIR for more information. There is a special class of filters for this called polyphase filters. Because you're going to throw away 3 out of 4 samples there's no need to calculate them. This might be a good idea for downsampling because you need a very steep filter slope there.ĭownsampling is sort of a special case. The're generally the same idea but IIF filters use feedback loops to achieve a steeper response with far less coefficients. Using DFT's for filtering is generally overkill and it makes things more complicated because dft's are not a contiuous process but work on buffers.ĭigital filters generally come in two tastes. There are fixed point filter algorithms too but those generally have quality tradeoffs to work. It's a good idea to do the filtering with floats. Any signal over 5500 Hz will be present in your downsampled signal but 'aliased' as another frequency so you'll have to remove those before downsampling. You're right in that you need apply lowpass filtering on your signal.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |