Electronic – the difference between a 1st and 2nd Order Digital Filter

controldigital filterfiltertransfer function

I was just curious as to the differences between the two order filters?

How I created these discrete filters for references

  • Designed in Continuous first then converted into Discrete

  • Using Tustin's method as I just want to convert the plant from continuous to discrete

  • Fc = 20kHZ

  • Used Prep warping nyquist frequency = 20kHZ (Sampling at Ts = 0.000025/40kHz)

Filter 1: 2nd Order Butterworth filter Analog

enter image description here

Filter 1A: 2nd Order Butterworth Filter Discrete

enter image description here

Filter 2: 1st Order RC Filter Discrete

enter image description here

As you can see in Filter 1A I was shocked to see that "Brick-wall" response and was curious to see what if I used a lower order filter.

In Filter 2 you can see a similar result. The only difference I can tell is that magnitude (dB). The 1st Order filter has a flatter pass band then the 2nd Order Butterworth Filter.

Is there any advantage in using a higher order filter when it comes to discrete? Why in discrete the "Brick-Wall" response is much more apparent now when its only a 2nd Order.

Let me know if I even approached this correctly has I haven't dont discrete in a long time, so I wouldn't be surprise if something went wrong.

Bonus question, why when I try to do a step response for both filters I get this:

enter image description here

Another question that came to mind: Could we use the Sampling time to essentially change the Cut off frequency then?

EDIT: Looks like my Sampling times are wrong no idea what I am doing anymore. How do you know which Sampling Time is suitable for you? Or is that the trade off sacrifice how close it looks to the continuous for sampling times

Code:

%% -- Low Pass Filter (LPF) -- %%
R1 = 15000;
R2 = 9100;
C1 = 0.001*10^-6;
C2 = 470*10^-12;

LPF_A = ((1)/(C2*R1*s + C2*R2*s + C1*C2*R1*R2*s^2 + 1));
opt = c2dOptions('Method','tustin','PrewarpFrequency',125663.706);
LPF_D = c2d(LPF_A,0.000025,opt);

Best Answer

I don't have Matlab, but looking at their online help for c2d and c2dOptions:

'FractDelayApproxOrder'

Maximum order of the Thiran filter used to approximate fractional delays in the 'tustin' and 'matched' methods. Takes integer values. A value of 0 means that c2d rounds fractional delays to the nearest integer multiple of the sample time.

So, unless you have a need for a delay, you should set that to zero. The code should look like this:

opt = c2dOptions('Method', 'tustin', 'PrewarpFrequency', 0);
f0 = 80000;
opt = c2dOptions('Method', 'tustin', 'PrewarpFrequency', f0);
LPF_D = c2d(LPF_A, 1/f0, opt);

Let me know if this does it for you (I really don't have Matlab).


Re-read the online description, it looks like 'tustin' allows the 'PrewarpFrequency', so then you should match that with the c2d(), see updated code.