Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

First order digital filter

omid2006

Junior Member level 2
Junior Member level 2
Joined
Apr 24, 2019
Messages
20
Helped
0
Reputation
0
Reaction score
5
Trophy points
3
Activity points
120
Hello friends
I found a unknown digital low pass filter in a sample code but I can't adapt it's formula with common filters like IIR because it's like a IIR filter with negative coefficient. it's like feedback filter but feedback filter is a highpass in ordinary and this filter is low pass. I'll write it's formula and I appreciate if anyone can help.

Code:
out[n]+=(in[n]-out[n-1])*500*Ts

and Ts is the sampling frequency thus execution rate of filter.
 
Hi,

please give a reference where this formula is from.

I doubt:
* that Ts here is the sampling frequency ... especially here multiplying the sampling_frequency makes no sense (on first sight)
* that the value of "500" is useful. I expect useful values in the range of 0...1.

Klaus
 
The orginal code is from ST motor control library. but I've seen another type of this filter in another code too. it makes sense conceptually. it reduces the effect of new sample on filtered value.

1726138391686.png
 
Hi,

you think both post#1 and post#3 show the same?

post#2 shows a low pass like I use it for decades.
And here "t" is a representation of a time (time constant) ... surely not sampling_frequency.

and where does this "x" now come from? ... or where is it used at?

Again: post a link. So we all can talk about the same context.

Klaus
 
Use Excel to generate a discrete time sequence based on Z and Z-1 values.

Supply a step into filter to get a feel for time domain response.

Or use MATLAB Simulink to sim equation.


Regards Dana.
 
Hello friends
I found a unknown digital low pass filter in a sample code but I can't adapt it's formula with common filters like IIR because it's like a IIR filter with negative coefficient. it's like feedback filter but feedback filter is a highpass in ordinary and this filter is low pass. I'll write it's formula and I appreciate if anyone can help.

Code:
out[n]+=(in[n]-out[n-1])*500*Ts

and Ts is the sampling frequency thus execution rate of filter.
That equation reminds me of the leaky integrator(LPF):
yn = xn+ yn-1 i.e. current output = last output plus current input.
you can also use weights for input/output to target unity dc gain:
yn = alpha*xn + (1-alpha)*yn-1

However your equation shows negative y(n-1) so likely it is high pass filter with unknown weight on y(n-1) and no weight on xn
 
I doubt:
* that Ts here is the sampling frequency ... especially here multiplying the sampling_frequency makes no sense (on first sight)
* that the value of "500" is useful. I expect useful values in the range of 0...1.
Read Ts as sampling interval, 500 as cut-off omega, a valid estimation if Ts*omega << 1. Exact formula uses an exponential function.
 
I think this is correct sim (MATLAB Simulink) :

1726175211570.png



The input, the constant, functions as a step input. Looks like after 20 samples its settled to final value.
Strong LPF characteristic.

Pole/zero plot might be instructive as one plays with Ts.....


Regards, Dana.
 
Last edited:
I did miss that, here added is a unit delay to each fdbk path to
kill the algebraic loop caused by adder/product fed back to itself,
thanks for catching the error, caused by the += .

1726182204271.png



If I get a chance I will verify sample set generated with Excel solution. Better yet let OP
choose the correct Ts and generate the sample set himself.....


Regards, Dana.
 
Last edited:
I did miss that, here added is a unit delay to each fdbk path to
kill the algebraic loop caused by adder/product fed back to itself,
thanks for catching the error, caused by the += .

View attachment 193841


If I get a chance I will verify sample set generated with Excel solution. Better yet let OP
choose the correct Ts and generate the sample set himself.....


Regards, Dana.
I have never seen filter equation as += so I can't understand its meaning but surely it implies one delay unit as there is ( n) and (n-1) index but no (n-2).

It looks weird if I have to subtract the output from input then in the same calculation add the result back to output.
But the mystery is in the mind of beholder.
 
Not expert here but if I add equal unit delays (which is what I did) to all paths the group
delay of filter is affected, but not the magnitude behavior of it ? So its latency is affected
but not response.....

Knight
 
Not expert here but if I add equal unit delays (which is what I did) to all paths the group
delay of filter is affected, but not the magnitude behavior of it ? So its latency is affected
but not response.....

Knight
Ok but that means second order IIR and this is what I expect in hardware (FPGA/ASIC) for second order. In software, it seems in OP equation they can go for combinatorial feedback so you can add a scaled version of (x( n) - y(n-1)) back to y( n) but I got no idea why would anyone do that.
 
No doubt that original equation is first order and involves one and only one unit delay.

+= is unary operator in C, post #1 equation can be rewritten
out[n]=out[n-1]+(in[n]-out[n-1])*500*Ts
 
I think expanded equation should be (first term sample point in time changed) :

out[n]=out[n]+(in[n]-out[n-1])*500*Ts

Its that term in sim that caused me issue, which MATLAB states to add a unit delay in all paths
to cure. Basically fix unsolvable algebraic loop.

Response I get :

1726231897496.png


Knight
 
Last edited:
No doubt that original equation is first order and involves one and only one unit delay.

+= is unary operator in C, post #1 equation can be rewritten
out[n]=out[n-1]+(in[n]-out[n-1])*500*Ts
That reduces to, assuming Ts =0.001:
out[n] = (out[n-1] +out[n-1)*0.5) +in[n]*0.5
so for matlab freqz
num = 0.5
den = [1, -(1+0.5)]
freqz(num,den)
1726233776295.png
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top