damping filter - finite stationary error

Started by max3031 2 weeks ago13 replieslatest reply 1 week ago83 views


I need to make a damping filter that will produce for the given input signal desired output.  In the desired output there is always some stationary error that never dies out. In the attach is shown one test case, where blue signal is the input while the red signal is the desired output. input-output.PNG

How is this possible to achieve with damping filter? I tried with simple first order IIR filter but this filter always converges to the input blue signal while I need to preserve that finite error.

Here are the details. Script for processing is here I tried to dampen response but was unable to obtain desired output. Also here are the input data input.txt, what needs to be obtained or desired output output_desired.txt and my output obtained with the python script my_output.txt. Here is also visual comparison of these signals signal_comparison.png. I would like to obtain same or close response as in the output_desired.txt. 

I think that this is a proportional control with additional derivative perhaps ( P or PD control). That is why there is a stationary error in my opinion.

Control (P/PD/PID) and filtering is the right combination for this problem in my opinion. Only filtering with simple limiter as suggested is not the solution.

[ - ]
Reply by lamabrewNovember 26, 2019

Total W.A.G. here since there's no details as to what is meant by damping filter, nor code, etc, but looking at that plot it looks like maybe you have 8 bit math going on? So the filter coeffs are no where near 'exact' for unity gain?

[ - ]
Reply by max3031November 27, 2019

Details are provided.

[ - ]
Reply by bholzmayerNovember 27, 2019

I agree with lamabrew. Your inputs are very little, so you cannot expect much help.

But given that you cannot change the resolution, the result seems perfectly filtered.

If you want the steps removed, you might want either:

  • something like smoothing, which means you'd sacrifice exactity for the visual effect
  • higher resolution (in horizontal means higher sample rate, in vertical means more bits)

If your ADC (or whatever your input comes from) does not provide more bits, one thing which you can do is simply extend the measure values from 8 to 16bits, then have your filter calculations done with 16bits. This will give you smaller vertical steps.

If 16bit math is not possible/available within the filter, a cheap (but not so good solution) would be to just average the input, because obviously the input is already the same as the output except that it "jitters" between two amplitude steps.
A "Sliding Average" might help you with very little effort.

[ - ]
Reply by max3031November 27, 2019

Details are provided now. Sorry for the first post that did not include them.

[ - ]
Reply by dudelsoundNovember 27, 2019


While I agree with the others that your resolution is very low and I don't know exactly what you try to achieve, but your desired signal looks pretty much like your filtered signal with a limiter. So if you limit your filtered signal at desired_signal_max and desired_signal_min you'll be a lot closer...


[ - ]
Reply by max3031November 27, 2019


[ - ]
Reply by dudelsoundNovember 27, 2019

A simple brick wall limiter would be implemented like this:

if (filtered_signal[k] > desired_signal_max)
    filtered_signal[k] = desired_signal_max;

if (filtered_signal[k] < desired_signal_min)
    filtered_signal[k] = desired_signal_min;

[ - ]
Reply by max3031November 27, 2019

And how to obtain desired_signal max? I don't have that information. All I have is the input signal from input.txt. That is why I told you it can be achieved with PID or similar. Not with such simple heuristics as you are suggesting.

[ - ]
Reply by chalilNovember 27, 2019

Hi, may not be an helpful tip. just curious, Looking at the data, the system doesn't seems to be linear. for example, the DC gain or steady state gain is not same for the upper half and lower half.

x y gain
70.661 70.758 1.001373
70.648 70.651 1.000042

if not expected to be linear, you can put a median or moving ave filter followed by a limiter.  

[ - ]
Reply by max3031November 27, 2019

There is moving average if you take a look at the provided code. Limiter does not sound good.

[ - ]
Reply by max3031November 30, 2019

Ok I can accept that system is non-linear and that there is some kind of limiter. But the question is how to implement that? I am not interested in some simple ad-hoc solutions but the optimization techniques and close-source libraries that can handle this in a smooth way. Any idea?

[ - ]
Reply by chalilDecember 2, 2019

as any other system, if you can define the IO transfer characteristics right you're half done. a non-linear system of this type can be defined by a combination of linear (filter) canscaded with a non-linear (limiter). one can specify them and design them individually for most of the cases. for example, 


note : first part of the image taken from url

[ - ]
Reply by CedronDecember 2, 2019

I'm just looking at your charts without diving into the gory detail.  Nobody has uttered the magic words "median filter" yet so I thought I would.  Those look like rescaled median filters to me.