Digital Averaging Filter
Contents Background Design& Implementation Refine Discussion
What’s RMS (Root Mean Square) RMS is the constant value that yields the same power dissipation as the timeaveraged power dissipation of the signal For continuous signal
f rms
2 T2 1 f (t ) dt T2 T1 T1
For 1 cycle sinusoidal signal
RMS
f0
T1 1 f 0
T1
A cos ( 2 π f 0 t ) dt
2
A 2
What’s Average Average is the DC component of the signal For continuous signal
f avg
T2 1 f (t )dt T2 T1 T1
For 1 cycle sinusoidal signal (abs)
AVG f 0
T1 1 f 0
T1
A cos ( 2 π f 0 t ) dt
2 A
RMS vs. AVG For 1 cycle sinusoidal signal (abs)
RMS
A 2
AVG
2 A
If we know AVG, we know RMS
RMS
2 2
AVG 1.11072 AVG
Get Average in Analog World To get abs -> Rectifier
To get DC component -> Low Pass Filter
Get Average in Digital World To get abs -> Reverse the sign of negative sample
To get DC component -> Digital Low Pass Filter
Reverse Sign Reverse the sign of negative sample DC component is average value Cons - Introduce harmonics - Low precision in case of high harmonics Pros - No impact by a variety of frequency - No impact by a variety of initial phase angle MATLAB Example - a_ReverseSign.m
Design LPF– Overview Find a continue-time filter model, create transfer function Convert continue-time transfer function to discrete-time transfer function Write difference equation from discrete-time transfer function Difference equation can be implemented by program.
Design LPF– Continuous-Time Model Design a simple analog filter
Find transform function in s domain (Laplace Transform)
1 1 c H a ( s) s C R C 1 1 s c R s s C R C
Design LPF– Discrete-Time Model Convert Ha(s) to H(z) The convert method - Impulse invariance (DC gain is not 1)
A H a ( s) k k 1 s skH a ( s)
N
H ( z)
Ts Ak sk Ts z 1 k 1 1 eN
c s c
H ( z)
1 e c Ts z 1
c Ts
- Bilinear transform (DC gain is 1)
2 1 z 1 s Ts 1 z 1H a ( s)
2 1 z 1 H ( z) H a ( ) Ts 1 z 1
c s c
c Ts c Ts z 1 p p z 1 H ( z) 2 c Ts (2 c Ts ) z 1 1 (1 2 p) z 1
p
c Ts 2 c Ts
Design LPF– Difference Equation From H(z) to Difference EquationH ( z) b(1) b(2) z 1 ... b(nb 1) z nb X ( z ) Y ( z) 1 a(2) z 1 ... a(na 1) z na
Y (n) b(1) * X (n) b(2) * X (n 1) ... b(nb 1) * X (n nb ) a(2) *Y (n 1) ... a(na 1) *
Y (n na )
Design LPF– Difference Equation (cont’d) Impulse invarianceH ( z) 1 e c Ts z 1
c Ts
Y (n) c Ts X (n) e c Ts Y (n 1)
c Ts c Ts z 1 p p z 1 H ( z) 2 c Ts (2 c Ts ) z 1 1 (1 2 p) z 1 Bilinear transform
p
c Ts 2 c Ts
Y (n) p X (n) p X (n 1) (1 2 p) Y (n 1)
p
c Ts 2 c Ts
Implement LPF (Impulse invariance) MATLAB Example - b_ImpulseInvariance.m - Multiplication X 2 - Add X 1 Problems - The result is not stable (Filter is not ideal) - Multiplication operation costs too much CPU time
Design stable LPF Decrease cutoff frequency is not a good idea due to the long stable time Use cascading filters n Order -> -dB X n Y1(n) c Ts X (n) e c Ts Y1(n 1)
Y 2(n) c Ts Y1(n) e c Ts Y 2(n 1)
Y 3(n) c Ts Y 2(n) e c Ts Y 3(n 1) MATLAB Example - c_CascadingFilters.m
Design LPF without Multiplication Zero-Init Response& Zero-State Response
kTs kTs - Ts
vzi (t ) vo e
t R Ct t
1 vzs (t ) h(t ) (vi (t )) vi h( ) d vi e R C d vi (1 e R C ) 0 R CTs R C
t
vzi (kTs ) vo (kTs Ts ) e
vzs (kTs ) vi (kTs Ts ) (1 e
Ts R C
)
Design LPF without Multiplication (cont’d)●Write difference equation from response equation
vo (kTs ) vzi (kTs ) vzs (kTs ) vo (kTs Ts ) e
Ts R C
vi (kTs Ts ) (1 e
Ts R C
)
vo (k ) vo (k 1) e
Ts R C
vi (k 1) (1 e
Ts R C
)Exponential smoothing/wiki/Exponential_smoothing
Y (n) X (n 1) (1 ) Y (n 1) 1 e Ts c
Design LPF without Multiplication (cont’d)●Multiplication is replaced by bit-shift - Bit-Shift X 1 - Add X 2
Y (n) (( X (n 1) Y (n 1)) p) Y (n 1) 2 p●Cutoff frequency
c Fs ln(1 2 p ) fc 6.2414 T 5000, p 7 2 2 s
●MATLAB Example - d_ExponentiallyWeightedMovingAverage.m
Noise DC offset - Can be removed with an addition cascading filters Normal Distributed Noise - Some impact to average value Harmonics - Huge impact to average value MATLAB Example - e_ImpactFromNoise
Other Ways to Design Filter MATLAB Transfer Function Example - f_MatlabFilter.m MATLAB Filter Function butter -> Butterworth filter design cheby1 -> Chebyshev Type I filter design (pass band ripple) Window design method ( Finite Impulse Response )