Convert IIR to linear phase FIR
-
- KVRist
- Topic Starter
- 37 posts since 18 Sep, 2011
Hi,
I want to convert a IIR Filter into a linear phase FIR with the same magnitude response.
One method is, to just take a impulse response (filter 1 sample impulse) and then reverse it, and filter it with the same IIR again.
But then the magnitude is squared, because the filter is applied two times (forward/backward)
How can I square root the magnitude?
Maybe :
ForwardFFT -> transform magnitude (square root)* -> InverseFFT
*But how i exactly do this?
I want to convert a IIR Filter into a linear phase FIR with the same magnitude response.
One method is, to just take a impulse response (filter 1 sample impulse) and then reverse it, and filter it with the same IIR again.
But then the magnitude is squared, because the filter is applied two times (forward/backward)
How can I square root the magnitude?
Maybe :
ForwardFFT -> transform magnitude (square root)* -> InverseFFT
*But how i exactly do this?
- KVRist
- 296 posts since 1 Apr, 2009 from Hannover, Germany
No need to do that. Just sample the impulse response, take an FFT, zero the phase term, iFFT and swap halves of the FFT window.
- KVRist
- 296 posts since 1 Apr, 2009 from Hannover, Germany
No, zeroing the phase means setting the real part to the magnitude value (Sqrt(Re^2 + Im^2)). That'll zero the phase term while maintaining magnitude.
You can also make every odd bin value negative before doing the iFFT, that way you don't have to swap the frame halves afterwards.
You can also make every odd bin value negative before doing the iFFT, that way you don't have to swap the frame halves afterwards.
-
- KVRist
- Topic Starter
- 37 posts since 18 Sep, 2011
>No, zeroing the phase means setting the real part to the magnitude value (Sqrt(Re^2 + Im^2)).
Thank you very much for taking the time to answer me
Does the imaginary part remain, or do I have to replace it with zeros?
Also, before i do the first FFT, i think i have to put a window on impulse response (because its infinite)
So is it okay, to fill the input array of the FFT with the full IR (from the beginning on, zero padded) and multiply it with the second half of a window function (because it already begins with silence)
or
Put the IR in the middle of the input array (begins from the center) and multiply with a full window, for best precision.
Thank you very much for taking the time to answer me
Does the imaginary part remain, or do I have to replace it with zeros?
Also, before i do the first FFT, i think i have to put a window on impulse response (because its infinite)
So is it okay, to fill the input array of the FFT with the full IR (from the beginning on, zero padded) and multiply it with the second half of a window function (because it already begins with silence)
or
Put the IR in the middle of the input array (begins from the center) and multiply with a full window, for best precision.
-
- KVRAF
- 2256 posts since 29 May, 2012
-
- KVRist
- Topic Starter
- 37 posts since 18 Sep, 2011
Hi Stratum,
thanks for your advice, i know this book, i know how to make a custom filters, which is basically the second part of the answer of my first question (using the magnitude as real) but it not covers my all *very specific* questions, from my last post. Maybe I'm just too stupid, so basically i want to go sure.
I want to convert a IR of an IIR into a linear phase FIR.
I put the IR (which i made from the IIR) into a buffer (the longer the buffer is, the better result).
One question was, whats the effective way of doing it? For best speediness and accuracy.
I have to fade-out the IR somewhere, if not, i have a high frequency peak.
Than after the FFT, i use the magnitude as real and zero as imaginary part(i guess), and use the same method (custom filters) as mentioned in the book (or make every odd bin value negative, to save the swap)
thanks for your advice, i know this book, i know how to make a custom filters, which is basically the second part of the answer of my first question (using the magnitude as real) but it not covers my all *very specific* questions, from my last post. Maybe I'm just too stupid, so basically i want to go sure.
I want to convert a IR of an IIR into a linear phase FIR.
I put the IR (which i made from the IIR) into a buffer (the longer the buffer is, the better result).
One question was, whats the effective way of doing it? For best speediness and accuracy.
I have to fade-out the IR somewhere, if not, i have a high frequency peak.
Than after the FFT, i use the magnitude as real and zero as imaginary part(i guess), and use the same method (custom filters) as mentioned in the book (or make every odd bin value negative, to save the swap)
- KVRist
- 296 posts since 1 Apr, 2009 from Hannover, Germany
Yep, that's basically it. For the windowing: yes, you should window the original impulse response, which will alter the result a bit. But if the IR is long enough, you might not need to. The lower the impulse response level at the end of the buffer, the better. If you can make it long enough so you don't cut much away at the end, it's usually better to go with rectangular window, because the rest isn't affected. If you cut a significant amount of information, you should use a smooth window to make the artifacts a bit nicer.chipnix wrote: Than after the FFT, i use the magnitude as real and zero as imaginary part(i guess), and use the same method (custom filters) as mentioned in the book (or make every odd bin value negative, to save the swap)
-
- KVRAF
- 2256 posts since 29 May, 2012
Do not forget to test the filter as described in the book as the method depends on the *inability* of a short impulse to match the sampled spectrum. If the impulse you use is too long, it may not match the spectrum you want. If it is too short, this time the bass part will not match.
~stratum~
-
- KVRist
- Topic Starter
- 37 posts since 18 Sep, 2011
> If it is too short, this time the bass part will not match.
I agree! Also the smaller the kernel, the less steep a filter can be.
> If the impulse you use is too long, it may not match the spectrum you want
As i understand, its important that the FFT-size which is used to calculate the FIR kernel, must be higher than the used filter kernel itself. From that point, i think there is no problem to use very long filter kernels (they will be just more precise), as long the used FFT-size is as many times higher than the filter-kernel itself.
I agree! Also the smaller the kernel, the less steep a filter can be.
> If the impulse you use is too long, it may not match the spectrum you want
As i understand, its important that the FFT-size which is used to calculate the FIR kernel, must be higher than the used filter kernel itself. From that point, i think there is no problem to use very long filter kernels (they will be just more precise), as long the used FFT-size is as many times higher than the filter-kernel itself.
-
- KVRAF
- 2256 posts since 29 May, 2012
Ch17 states that that extra precision will be a problem at some point because the filter specification is samples at frequency domain. Points between the samples are not specified. Your approach may be a solution, as it makes sense, but make a test in any case by zero padding as described.As i understand, its important that the FFT-size which is used to calculate the FIR kernel, must be higher than the used filter kernel itself. From that point, i think there is no problem to use very long filter kernels (they will be just more precise), as long the used FFT-size is as many times higher than the filter-kernel itself.
~stratum~