# Biquad coefficients using Magnitude (or Phase) Invariance Mapping Method

I'm trying MIM (Magnitude Invariance Method) and PIM (Phase Invariance Method) for to improve biquad LPF response at low sampling rates. I'm looking some help and examples of usage if available.

EDIT_1: I tried MIM method for 2nd order

LPF
fs=44100
fc=15000
Q=0.707


and

Peak filter
fs=44100
fc=10000
Q=0.707
db=6


Here are the resulting plots:

Responses looks promising.

Example code (LPF):

% Analog model for LP filter:
fs = 44100;
fc = 10000;
Q  = 0.707;

w0 = 2 * pi * fc;
b2 = w0^2;
a2 = [1 w0/Q w0^2];
Ds = tf(a2, b2);

% Calculate coefficients using MIM
[Dz] = c2dn(Ds, fs, 'mim', 2, 4096*256);

bodemag(Ds, 'r', Dz, 'b');

• What is MIM? PIM? What have you tried to implement? – Peter K. Jul 10 '16 at 16:39
• Matlab and Octave are very similar. Just try running the code and ask about errors on StackOverflow. – Peter K. Jul 14 '16 at 12:08
• Sorry! I've been traveling. Can you post your solution as an answer here? Thanks! – Peter K. Jul 17 '16 at 8:40

2nd order MIM LPF results looks great for selected cutoff frequency (fs = 44.1kHz) as seen in plot (frequency range upto 23873Hz):

Coefficients for plotted 2nd order filter:

a [0.437417389844334 0.1220119196463959 -0.04071587087954469]
b [1 -0.6951293456643256 0.2138427842755107]


EDIT:

It looks like there are some problems in magnitude response when fs is increased and/or when fc is reduced. MIM/PIM paper mentions this as an issue.

So, it looks like MIM can be used for to improve 2nd order LPF magnitude response especially when using low fs and high enough fc. Magnitude issues can be bypassed by using higher order filters. Fortunately MIM method works correctly for my purposes.

EDIT: First and the second D(s) given in paper examples are wrong. The correct ones are (5s + 2) and (s + 10) / (s^2 + 4.1s + 0.4). With those all the MIM calculations become right. The third example (PIM) was correct.