Low pass digital filter not working as expected

Hello all, thanks for your comments, Peter/Pandiani/L D[AR2,P#0.0], it is great to have such a good community here on PLCs.net

The PLC is processing every 1ms but the data from the serial motion sensor is updated every 20ms (50Hz)

The digital filter function block has these inputs for testing:-


tTaskCycleTime : Cycle time with which the function block is called. If the block is called in every cycle this corresponds to the task cycle time of the calling task.
tCtrlCycleTime : Cycle time with which the control loop is processed. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.

so the task cycle time (tTaskCycleTime ) is set to 1ms and the control loop sample timer (tCtrlCycleTime) to 20ms.

To simplify for testing, I have made the function block call every 20mS therefore the function block is called when the data is updated.
Now both tTaskCycleTime and tCtrlCycleTime are 20ms.


Thanks for the code [AR2,P#0.0]. I will try that and compare. That site what derived the coefficients, 8000 sample a second is extremely high. The way it was written, I assumed this sample frequency was for the plot only and not for the coefficients calculation.


I stand corrected, filter:
simple second order digital filter would look like this:
0.2929 z^2 + 0.5858 z + 0.2929
------------------------------
z^2 + 0.1716

This means:
b1 = 0.29229
b2 = 0.5858
b3 = 0.2929

a1 = 1;
a2 = 0;
a3 = 0.1716
requires 20 Hz sampling rate and not 10 Hz.

Matt, can you provide us with feedback? Did you try this?

Hello Pandiani, yes I have tried these values and the filter is doing some filtering but only a little bit, there is still quite a lot of this high frequency noise.

I will work on this and post more results when found.

Regards

Matt

filter test1.jpg
 
Matt,

if everything is set to 20 ms update time, please, try these coefficients:
B = 0.0675 0.1349 0.0675

A = 1.0000 -1.1430 0.4128

Bode plot is given in attachment. Its cutoff frequency is 5 Hz (-3 dB) and characteristic is very steep from that point.

Are you sure about 0-5 Hz pass band?

Bode2.jpg
 
That still doesn't look right Pandiani

The coefficients are right but the graph is wrong.
The attenuation should be so many db per decade. You filter drops too sharply. I think your frequency scale is plotted correctly.

See my Bode plots
ftp://ftp.deltacompsys.com/public/NG/Mathcad - Butterworth NG.pdf

I introduced random noise on top of a 1 Hz sine wave.

Note I used matched Z transforms, MZT, instead of Tustin's approximation. MZT doesn't introduce zeros in the z domain, has fewer coefficients and doesn't need frequency warping.
 
Peter,

Bode plot is right, I'm sure. Maybe it's just because of the scale.
Transfer function is:
0.0675 z^2 + 0.1349 z + 0.0675
------------------------------
z^2 - 1.143 z + 0.4128

Sampling time: 0.02

I've used built in function (Matlab) to make bode plot. This is the same plot but with different scale (y axis). Look and compare it.

Bode3.jpg
 
Matt,

if everything is set to 20 ms update time, please, try these coefficients:
B = 0.0675 0.1349 0.0675

A = 1.0000 -1.1430 0.4128

Bode plot is given in attachment. Its cutoff frequency is 5 Hz (-3 dB) and characteristic is very steep from that point.

Are you sure about 0-5 Hz pass band?

Hello Panadiani,

see attached with these coefficients. The low pass filter is certainly working better.

What I will do now is use these coefficients and make the input a sine wave at various frequencies then I can see if this filter is working easily rather than using my noisy input signal.

Thanks

Matt

pandiani #18.jpg
 
Hello Matt,
I'm glad it's better now. You can now play with it and see how it works. If you're not satisfied with the result then you need to estimate frequency spectrum of your signal and now in which range is your noise signal. Then, when you know for sure what is the range you want to filter out, design will be much easier.
 
Attached is the a sine wave input and with these values the filter is working correctly. I will try to find the ideal filter for this noise to see if I can improve the response.

Thank you everyone for all your help.

filter with sine wave input.jpg
 
Hello L D[AR2,P#0.0],

I tried the filter code you provided thank you. Below are the results in green. The result is very similar to the Beckhoff one, with Pandiani coefficients. There is just a slight higher lag.

Thank you

Matt

filter LD AR2.jpg
 

Similar Topics

We have to program a low pass first order filter in Siemens S7. From an engineering company we got following transfer function ...
Replies
10
Views
7,303
I am trying to play with LPF block in the PLC. I was playing with the values of omega (w) to see what changes i can witness. So far I have found...
Replies
12
Views
4,482
I'm working on an improvement project that has me a little confused. Weighing product throughput and then adding other ingredients based on that...
Replies
2
Views
2,193
Hi, I need to use 3 filters in my s7300 PLC. These are Low Pass, High Pass, Notch, but there are in the library of STEP 7. I saw these filters in...
Replies
2
Views
6,442
I have done the searches and the closest to what I was looking for was here- Low-pass Filter . But still no help. My case- About a year ago I...
Replies
7
Views
2,568
Back
Top Bottom