Frequency response of all pass filter is not great
-
- KVRer
- 4 posts since 10 Feb, 2010
I have a first order allpass filter with difference eq:
y[n] = ax[n] + x[n-1] - ay[n-1]
This is all pretty standard (shift the negatives and positives around depending on your source material)
Anyway, I ran this filter through MATLAB with a=1 and was surprised to find that the frequency response is not anywhere near as flat I was led to believe it was.
Can someone tell me how close this type of first order filter gets to the ideal frequency response? Have I stuffed up my MATLAB usage or am I expecting too much?
Thanks
y[n] = ax[n] + x[n-1] - ay[n-1]
This is all pretty standard (shift the negatives and positives around depending on your source material)
Anyway, I ran this filter through MATLAB with a=1 and was surprised to find that the frequency response is not anywhere near as flat I was led to believe it was.
Can someone tell me how close this type of first order filter gets to the ideal frequency response? Have I stuffed up my MATLAB usage or am I expecting too much?
Thanks
- KVRAF
- 8511 posts since 12 Feb, 2006 from Helsinki, Finland
If you're plotting the magnitude response with automatic y-scaling then remember to check what you actually get; I don't know about MATLAB but a whole lot of packages will actually give you a "y-scale" that has label "1" next to each tick.. and then proceed to plot numerical errors (ie the tiny deviations from 1 that you get by numerically calculating the magnitude response). In many cases you can avoid that by plotting the response with another "reference function" (with the idea that the "reference" forces you a particular scale).
-
- KVRer
- Topic Starter
- 4 posts since 10 Feb, 2010
Thanks, mystran. No, MATLAB appears to have chosen sensible values for the y-axis.
The phase response of the filter is excellent and exactly what I expect, but the magnitude response is shaped somewhat like a low pass filter. There is a -3dB drop by the time we reach 11025Hz.
I'm pretty new to MATLAB so it's possible I'm stuffing it up somewhere, but I checked the pole/zero plot of the same filter and it is exactly what you'd expect from a first order all pass.
So, my current conclusion is that the filter is not quite as flat as I had always thought it was (certainly every text book I've read has never mentioned any shortcomings).
The phase response of the filter is excellent and exactly what I expect, but the magnitude response is shaped somewhat like a low pass filter. There is a -3dB drop by the time we reach 11025Hz.
I'm pretty new to MATLAB so it's possible I'm stuffing it up somewhere, but I checked the pole/zero plot of the same filter and it is exactly what you'd expect from a first order all pass.
So, my current conclusion is that the filter is not quite as flat as I had always thought it was (certainly every text book I've read has never mentioned any shortcomings).
- KVRAF
- 8511 posts since 12 Feb, 2006 from Helsinki, Finland
Your conclusion is wrong. Consider:multiben wrote:Thanks, mystran. No, MATLAB appears to have chosen sensible values for the y-axis.
The phase response of the filter is excellent and exactly what I expect, but the magnitude response is shaped somewhat like a low pass filter. There is a -3dB drop by the time we reach 11025Hz.
I'm pretty new to MATLAB so it's possible I'm stuffing it up somewhere, but I checked the pole/zero plot of the same filter and it is exactly what you'd expect from a first order all pass.
So, my current conclusion is that the filter is not quite as flat as I had always thought it was (certainly every text book I've read has never mentioned any shortcomings).
y[n] = ax[n] + x[n-1] - ay[n-1]
Rearrange as follows:
y[n] + ay[n-1] = ax[n] + x[n-1]
Observe that the inverse of the poles is the time-reversal of the zeroes. Since time-reversal only affects phase (not magnitude) the magnitude response of the filter MUST be unity (at least before we consider numeric effects). If you're not convinced, you can take (analytic) z-transform and simplify in polar form until you get rid of all the magnitude terms (you can do this "for all a").
Observe though, that if abs(a) is very close to 1, then the impulse response will decay very slowly. If you try to analyze such a filter by taking the FFT of an impulse reponse (instead of using analytic z-tranform), you will not get a truly flat result, because the IR necessarily needs to be truncated; you can then flatten the results by increasing the FFT size. The filter is still totally flat, and if you insist on analyzing with an FFT (for example because you want to verify your implementation), then use a periodic excitation to build a steady-state and analyze that.
Finally, it's always possible that you just made a mistake.
-
- KVRer
- Topic Starter
- 4 posts since 10 Feb, 2010
Ok, it turns out I've been making a mistake in MATLAB. I was specifying the coefficients in the wrong order :/
Thanks for the help, mystran. Your last post convinced me that I was missing something. It's good to resolve it, although my head is in pain now.
Thanks for the help, mystran. Your last post convinced me that I was missing something. It's good to resolve it, although my head is in pain now.
