Linear Phase Frequency Variable filter

Hi all!

I would like to create a kind of frequency variable linear phase (low-pass or high-pass) filter and I am trying to find some best-approach to do this.

IIR Implementation

In general, I find the frequency-dependent coefficients of my IIR (first or second order) filter and then I apply some kind of all-pass filter to compensate for the linearity of the phase.
Might I ask if this is a correct approach? How can I find the coefficients of the all-pass filter?
IIUC, this solution does not introduce latency, but could highly affect the computational load.

FIR Implementation

In this case, I can find the N coefficients of my FIR filter with some pre-processing calculation (I could use some built-in MATLAB function to find the coefficients by specifying the cutoff, the sampling frequency, roll-off attenuation, etc… ). Since FIR coefficients are usually symmetric, the filter is usually linear-phase by design, even if it introduces some delay which depends on its length.
But how could I find a relation between the coefficients and the cutoff frequency in order to make it frequency variable in real-time?

I hope I was clear and please correct me if I wrote something wrong.

Thank you very much for your help

But how could I find a relation between the coefficients and the cutoff frequency in order to make it frequency variable in real-time?

The coefficients of the FIR are the impulse response itself, so you design your filter magnitude shape via standard math functions. (could be either a custom shape or a function that matches the magnitude of standard IIR filters), after what you sample that magnitude and do the ifft of it to get the impulse response which is your FIR coeffs. You may also perform the convolution in the frequency domain directly for speed if you get a large number of coeffs, so you don’t need to work with the impulse response and you can skip the ifft step. Also to prevent temporal aliasing, the magnitude you design should be smooth enough, and your impulse response long enough. Hope it helps.

1 Like

Hi @lcouka and thank you for your answer!

So if I am not wrong, when the user changes the cutoff frequency, the steps are:

  1. Recompute (and resample) my magnitude function
  2. Come back to the time-domain by doing the ifft
  3. Apply the filtering process in time-domain

It works fine in my mind, but I’m wondering if this process does not introduce an high computational load with respect to the IIR implementation.
Even if I work in the frequency domain, I need to do the fft of the input and the ifft at the output after the convolution. Isn’t it?

Please bear in mind that IIR filters only can give you at best minimum phase shifts, not a linear phase response. You need FIR filters for that, which may introduce some latency, whereas IIR latencies can be dismissed (a few samples at most).
FIR filters can have a audible side effects: “pre-ringing”. In practice IIR filters are more common and closer to analogue gear.

Cheers

1 Like

It works fine in my mind, but I’m wondering if this process does not introduce an high computational load with respect to the IIR implementation.

IIR are generally cheaper.

Even if I work in the frequency domain, I need to do the fft of the input and the ifft at the output after the convolution. Isn’t it?

Yes you do.

I would recommend to go on IIR for time varying filters, but you’ll not get the phase linear feature indeed.

1 Like

Ok, I got it. I was asking this because a lot of eq and filters on the market give the possibility of the linear-phase mode.

Thank you very much for your answers :slight_smile: