Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- deleted comment #1 ---------------
- -- in reply to https://www.youtube.com/watch?v=cD7YFUYLpDc&lc=UgwV5-is0eddFrrQy7F4AaABAg.9qWQuBn24EcA1MhCDC44wZ
- You can do something like that to quickly and easily produce a very sharp low-pass FIR filter, but it won't be a very good filter. The problem is that while this will construct a filter whose frequency response has the specified values at evenly spaced frequencies (multiples of sample rate / filter length), it will ripple quite badly in between them, especially near the transition from passband to stopband. For example say we want a 20 kHz lowpass at 88.2 kHz sample rate (for resampling between 44.1 kHz and 88.2 kHz) using a 255-point FFT (odd length avoids some headaches) then we need 117 ones and 138 zeros. The resulting filter has a passband ripple that reaches 1.14 dB (at 19.917 kHz) while the first stopband peak above 24.1 kHz (i.e. which at 44.1 kHz sample rate will get aliased below 20 kHz) is -36.3 dB at 24.382 kHz, and the stopband never gets much better, with the lowest peak being -45.6 dB at 44.1 kHz. Increasing the filter length does little to nothing to fix this problem.
- The main cause for this is the excessively sharp transition between the passband and the stopband (the last 1 and the first 0), which in this method only gets sharper as you increase the filter length. A second problem is that the ripple is not evenly distributed, which increases the magnitude of the worst deviation between the filter design specification and actual filter in each band of interest (which is how FIR filter design is commonly graded).
- Fortunately there is a really neat algorithm (Parks-McClellan) that allow you to specify the desired response for parts of the frequency spectrum and which will produce a linear-phase FIR filter of desired length that minimizes the worst deviation from the spec. For comparision I've used it to produce a slightly shorter low-pass filter (length 224) with less than 0.01 dB ripple in the 20 kHz passband, and a stopband from 22.05 kHz up where the filter response stays below -120 dB.
- --- deleted comment #2 ---------------
- -- (second attempt at the previous comment, phrased more concisely and with less numbers)
- That method of designing a FIR filter _kinda_ works (if you tweak some minor details) but it won't produce good results. Basically the issue is that you're specifying the exact value of the frequency response at each point of an evenly spaced grid of frequencies (all multiples of sample rate / filter length) but don't constrain the ripple it will have in-between those points, which will be much worse than it needs to be, especially since you're forcing an excessively sharp transition.
- To give some concrete numbers, say we want a 20 kHz low-pass at 88.2 kHz sample rate (the most critical filter for any oversampling DAC or ADC). Your method using 255 points yields a filter with a whopping 1.14 dB passband ripple and only 36.3 dB stopband attenuation (if we take the stopband to start at 24.1 kHz). This may be usable for a DAC but they're terrible specs for such a long filter (with associated high group delay).
- In contrast, using the Parks-McClellan filter design algorithm (the gold standard for linear-phase FIR design) you can produce a shorter filter that has less than 0.01 dB passband ripple and more than 120 dB stopband attenuation.
- --- deleted comment #3 --------------------------------
- -- in reply to https://www.youtube.com/watch?v=cD7YFUYLpDc&lc=UgwV5-is0eddFrrQy7F4AaABAg.9qWQuBn24EcA1SEESqf0qe
- Q and resonance aren't applicable concepts here since there's no feedback. The source of the frequency domain ripple of your filter is however very similar to the source of ripple in time domain if you were to toss such a sequence of ones and zeros into a DAC, except the role of time and frequency is swapped.
- An IFFT natively constructs a discrete periodic signal from its discrete periodic spectrum. When you use its output as a (non-periodic) FIR filter you're effectively windowing it in time domain with a rectangular window, which means you're convolving its spectrum with a sinc function.
- Another interesting way to look at it is that the spectrum of a symmetric finite discrete-time signal is a polynomial in cos(2π f / fS) so the ripple is the result of fitting a polynomial through the points you specified as input to the IFFT.
- --------------------------------------------------------------
- Also, I originally considered trying to include this link but abandoned that idea when even my link-free comments got deleted by youtube's idiotic filter: https://imgur.com/a/b24ezvq showing an example of a filter constructed with your method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement