1
\$\begingroup\$

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);
\$\endgroup\$
  • 2
    \$\begingroup\$ Since your transfer function doesn't look like a low pass filter and your step response is an increasing oscillating function, it seems that something went wrong in how you designed the filter. \$\endgroup\$ – user1850479 Mar 24 at 2:50
  • \$\begingroup\$ Hi! Thank you for replying. I can confirm its the right transfer function. More importantly if I increase the Sampling rate it now shows a proper step response. \$\endgroup\$ – Leoc Mar 24 at 2:58
  • \$\begingroup\$ Can you post the actual code? I can't make out the sampling frequency, is it 40kHz? Nyquist should be strictly greater than fc, not greater than or equal. Then Ts is 25us/40kHz=62.5ns? It's confusing. \$\endgroup\$ – a concerned citizen Mar 24 at 14:27
  • \$\begingroup\$ Yeah of course. Ill put in the main post. @aconcernedcitizen The code is there now \$\endgroup\$ – Leoc Mar 24 at 15:26
  • \$\begingroup\$ @user1850479 The analog filter clearly has a 2nd order magnitude/phase response, and a 2nd order polynomial at the denominator which, when calculated gives a perfectly good Laplace transfer function. The problem could not have been in the design, but in the transformation. \$\endgroup\$ – a concerned citizen Mar 24 at 16:50
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Well, in C2D options it does set FractDelayApproxOrder to 0 \$\endgroup\$ – Leoc Mar 24 at 16:25
  • \$\begingroup\$ @Pllsz See the updated answer. \$\endgroup\$ – a concerned citizen Mar 24 at 16:26
  • \$\begingroup\$ Just checked it. The Fc (Cut off Freq) is no where near the 20kHZ mark. Compare to the original code \$\endgroup\$ – Leoc Mar 24 at 16:27
  • \$\begingroup\$ The Nyquist frequency, f0/2, needs to be greater than fc, so 40kHz is way too low. Try 80kHz. Just realized I copy-pasted your values, without changing f0, as mentioned in the comments above. But if you really aim for a fairly good match in magnitude, f0 should be ~10 times more, if you can afford it. \$\endgroup\$ – a concerned citizen Mar 24 at 16:34
  • 1
    \$\begingroup\$ I don't know how to put this delicately, but it really looks like you lack some basic notions, so maybe it would be better to first read about signals and systems first, before digging into filter design teritory? This is a free online book. Otherwise this discussion will stretch at every step of an explanation with "but what is that?". \$\endgroup\$ – a concerned citizen Mar 24 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.