POCPA Conference20..23 May @ DESY
Michele Martino (TE-EPC-HPM)
CURRENT MEASUREMENT
DIGITAL FILTERING - TUTORIAL -
1
POPCA 2012
๐น (๐ง )=โ๐=0
๐
๐ ๐ ๐งโ ๐/1+โ
๐=1
๐
๐ ๐ ๐งโ๐พ๐
FIR or IIR?
CURRENT MEASUREMENT FOR CONTROL
2
voltage/current signal transmission
Converter
Control
CurrentTransducer
PowerCircuit
ADCAnti Aliasing
/ Signal
Conditioning
Control systems can tolerate some delay in the measurement chain but certainly donโt like it !
Fundamental trade-off of the measurement chain: accuracy vs speed !
Properly designed digital controllers can โeasilyโ handle delays (RST), so whatโs the problem?
Delays increase model order (Z transf) โ Model mismatch become rapidly critical for stability!
SAMPLING BASICS
3
๐ ๐ =1๐
Ideal Sampling
Time Domain Frequency Domain
Spectrum of a critically sampled strictly band-limited signal: no alias!!!
Signals whose bandwidth exceeds will be corrupted!
Noise is always present so there are no strictly band-limited signals! Anti-aliasing filtering always needed!
If the controller runs at , what about sampling faster?
Quantization Noise
QuantizationNoise
WHY OVERSAMPLING?
4
Standard Nyquist Sampling
Oversampling
High Order Analog Filters Huge Delay
Small Transition Bandwidth High Order Filter
High Order Analog Filters No re-configurability
Analog filter
๐ ๐
2๐ ๐๐๐ ๐ : frequency at which the control algorithm runs
Anti-aliasing can be dealt with only analogically!
Digital filter
Analog filter
๐ ๐๐๐ ๐ ๐ ๐
2๐พ ๐ ๐๐พ
๐ ๐
2๐พ ๐ ๐โ ๐ ๐๐๐ ๐ ๐ ๐
Anti-aliasing filtering can be shared between analog and digital!โQuantizationโ Noise decreases of a factor
increases by a factor , by
Re-configurability now possible
DECIMATION
5
Take the average of the samples?
๐ฆ ๐=1๐พ โ
๐=๐๐พ +1
(๐+ 1)๐พ
๐ฅ ๐
Ok oversampling works very well, but the control still runs at !!! Samples are produced at frequency, so what to do with them?
Take one sample out of ? Not really a brilliant idea
Replicas still occur due to decimation!
SNR not improved due to lack of filtering!
Thatโs better: it puts a notch at which can be the switching frequency of the converter!
๐พ=135๐ ๐=50kHz๐ ๐ =6750 kHz
Convolving many of such filters, notches can be put at pathological frequencies and enough attenuation can be achieved close to
๐ท๐๐๐๐ฆ โ ๐พ2samples
๐ท๐๐๐๐ฆ โ ๐ ๐
2
THE NEVER-ENDING DISPUTE: IIR VS FIR
6Charles M. Rader : The Rise and the Fall of Recursive Digital Filters โ IEEE Signal Processing Magazine,
Nov 2006
(non-causal)
FIR order / -taps IIR order (, )
0 500 1000 1500 2000 2500 3000 3500 4000-150
-100
-50
0
f [kHz]
Am
plit
ude [
dB
] A
rbitra
ry S
cale
Spectrum of : order
0 50 100 150 200 250 300 350 400 450 500-150
-100
-50
0
f [kHz]
Am
plitu
de [
dB]
Arb
itrar
y S
cale
Spectrum of : zoom
WHERE THERE IS NO MATCH AGAINST FIR:
7
1-bit ADC: 1-bit only?
+-
H(f)
+g
n
+1
-1
Vref = 1
1-bit D/A Kfcanaloginput
Yto digital filter
X1-bit
A/D converter
Yes, 1-bit only! It is the digital filter that actually determines the ADC โprecisionโ!
โshapesโ the white, uniformly distributed (pseudo-quantization) noise ! model
Fundamental relationship for digital filter design:
Only 1-bit means that no multiplication are needed for filters!!!!
๐๐ข๐ก [๐ ]=โ๐=0
๐
๐๐ ๐ฆ [๐โ๐ ] , ๐ฆ [๐โ ๐ ]=ยฑ1
HOW TO SPECIFY DIGITAL FILTERS
8
๐ด๐๐๐ ๐ =2|๐ ๐๐๐๐๐๐๐๐ฅ|๐๐ต=2 (1+๐ฅ๐๐๐ )๐๐ต
(1โ๐ฅ๐๐๐ )โค๐บ๐๐๐ ( ๐ )โค(1+๐ฅ ๐๐๐)
Idle tones can be close to so a w.c.
has to be guaranteed by the filter!
0 500 1000 1500 2000 2500 3000 3500 4000-150
-100
-50
0
f [kHz]
Am
plit
ude [
dB
] A
rbitra
ry S
cale
Spectrum of : order
๐๐๐๐ ๐๐น๐๐๐๐๐๐น๐ท๐
๐ธ๐๐๐ต=๐ ๐ผ๐๐ด๐ท๐๐ตโ1.76
6.02
๐ ๐ผ๐๐ด๐ท๐๐ต=1.76+120โ ๐ฅ๐๐ตโ 121.8โ๐ฅ๐๐ตโ๐ด๐ ๐ก๐๐=121.8โ๐ฅ๐๐ต
A precision of is required
- โalias-freeโ bandwidth
๐ ๐
โalias-freeโ bandwidth
โalias-freeโ bandwidth of the converter (no overspecs)
: why????
MINIMUM-PHASE FIR
Minimum-phase filters: the delay in the passband (approx constant) is significantly lower than that of a linear-phase having the same frequency constraints:
A minimum-phase filter has additional advantages; the overall order of the design is less than that of a linear-phase : coefficients which are less sensitive to quantization
filters can have a nice linear phase, but is that important?
, , , , ,
Linear-Phase Minimum Order Minimum-Phase Minimum Order
Ok it looks promising, but minimum-phase has a lot more overshoot! Is that a problem?
Actually not if the filter is part of the measurement chain of a control loop!!!
Minimum-phase FIR can readily be used in single-stage or multistage decimatorsโฆ That needs some tricks: , both and are not integers!
MINIMUM-PHASE FIR DECIMATION
Given the specifications a minimum-order minimum-phase with coefficients is calculated be means of FDATOOL โ Generalized Equiripple Algorithm If then a new filter can be designed with ; the output at frequency
can then be generated by simply taking one samples out of If then a new filter has to be designed with ; in order to guarantee the
minimum delay filters need to be interleaved
: wordlength, : fraclength Coefficients wordlength has to increase by bits
IIR IMPLEMENTATION
11
Implementation on DSP hints Hints based on Texas Instruments TMS320C28x with CCS
The hints clearly work with floating point DSP such as the TMS320F28335 _IQmpy โ *
No multiplication round-off errors if =
IIR IMPLEMENTATION
12
Implementation hints on DSP : Break up Structure and Combine Terms
IIR IMPLEMENTATION
13
Implementation hints on DSP : Inline
Inline is automatic with โO3 Optimization mode
Source must be visible to calling file
Make data allocation/definitions visible to calling file
Compiler can make use of Direct Addressing Mode โ@0..63
Two order filters + two -like controllers +โฆa bunch of other stuff running on a TMS320F28335
โINTERACTIVEโ SESSION
14
MATLAB FDATOOL
15
Different algorithms are available for minimum-phase design
Generalized Equiripple calculates minimum (even) order filters!
Other algorithms can be successfully used once the filter order is approximately known
What about very long filters?
For filter orders larger than a thousand taps the algorithms fail
But the problem can be decomposed and the FDATOOL let you the โcascadeโ
You can also quantize coefficients and then create a .coe file
SOME SUBTLE PHENOMENA
16
What can go wrong?
SOME SUBTLE PHENOMENA
17
It looks very nice isnโt it? It looks very โwhiteโ !!!!
SOME SUBTLE PHENOMENA
18
Letโs have a look at the histogram:
SOME SUBTLE PHENOMENA
19
Letโs have a look at the impulse response:
CASE STUDY
The designed filter: , , ,
CASE STUDY
The designed filter: , , ,
CASE STUDY
The designed filter: , , ,
CASE STUDY
The designed filter: , , ,
CASE STUDY
Actual implementation by means of interleaved filters: and last taps equal to
CASE STUDY
Actual implementation by means of interleaved filters: and last taps equal to
CASE STUDY
DC performance
CASE STUDY
AC performance
CASE STUDY
AC performance
Making hardware or perform measurements as flat as the digital filter may turn out to be unfeasible or unworthy!
CASE STUDY
Sine-fit Amplitude Estimation
Clock had to be โcorrectedโ by for the data to make sense!
REFERENCES
30
http://www.mit.bme.hu/books/quantization
IEEE Std 1241-2000 Standard for Terminology and Test Methods for Analog-to-Digital Converters
A. Tessarolo, Getting the Most from Your C Code on the TMS320C28xโข Controller Using Code Composer Studioโข
Delta-Sigma Data Converters Theory, Design, and Simulation. Norworthy, Schreier, Temes, IEEE โ Wiley-Interscience 1992
K. Steiglitz, T. W. Parks, and J. K. Kaiser, โMETEOR: a constrained-based FIR Filter design program,โ IEEE Trans. Signal Proc., vol 40, no. 8, pp. 1901-1909, Aug. 1992
Digital Filters with MATLABยฎ : Ricardo A. Losada, 2009, The MathWorks, Inc.
New class of recursive digital filters for decimation: Horacio G. Martinez and Thomas W. Parks, 1978, Rice University Electrical Engineering Dept. Huston
M. Martino, et al. โLow emission, self-tunable DSP based Stepping Motor Drive for use with arbitrarily long cables,โ IFAC Large Scale Systems Symposium, Villeneuve dโAscq, France, 2010
BACKUP SLIDES
31
MINIMUM PHASE FIR FILTERS
32
Delay is minimized, but there is a lot more overshoot! Is that a problem?
100A10A
HOW TO SPECIFY DIGITAL FILTERS? 1
33
From Precision to Filter Specs
Full scale is considered as the reference level part-per-million will always be referred to it; if a precision of is required an ideal quantizer would then need to have a quantization step such that the maximum quantization error would be
Passband ripple
In order to guarantee a dynamic precision of all over the โuseful bandโ the passband gain should change less than the precision required for a full scale signal.
Stopband attenuation
For the stopband attenuation an estimation of the noise โlevelโ to be rejected is required!
In a relatively โsilentโ environment assuming noise components (worst case scenario) would turn out in heavy and sometimes meaningless over-specification complexity, computational power, delay!
Putting it (almost) all together
As an example if the expected, or measured, noise โlevelโ ( amplitude) is times smaller than the , then should be specified smaller than what is reported in the table. So precision can be achieved with only of attenuation in the stopband and so on. This will save computational power and most important: delay!
HOW TO SPECIFY DIGITAL FILTERS? 2
34
From Precision to Filter Specs
Stopband attenuation w.c.
: quantization noise power of an ideal quantizer with quantization step
]1.74 x 10-5
1.74 x 10-4
1.74 x 10-3
Whatโs still missing? Oh yes: passband and stopband frequencies!!!
The easiest approach (minimum filter order - largest transition bandwidth):
end of passband โalias-freeโ band beginning of stopband โalias-freeโ band
The iterative approach: beginning of stopband โalias-freeโ band
Replicas occurring around will not affect the desired precision in the โalias-freeโ band : โ โ delay โ ; โ โ โ โ order โ
should be chosen by trading off delay and filter complexity!
HOW TO SPECIFY DIGITAL FILTERS? 3
35
From Precision to Filter Specs
Now we are done! Or maybe not?
Letโs see: what about the โalias-freeโ band? โalias-freeโ band results in over specifying
โalias-freeโ band (full precision might not be needed for the whole closed loop bandwidth especially for very high precision applications)
WHY OVERSAMPLING? 1
36
A โbitโ of theory
Pseudo Quantization Noise model:
Still a bit too complicated Now the model is linear!
: Uniform Statistical Distribution White Independent of input signal
Quantization Process Quantization is a non linear process - vast and tricky subject Quantization of a signal Sampling its (Probability Density Function) Fortunately an approximated model works very well almost every
time!
Ok but what does that mean? Power of does not change with sampling frequency ideally
so increasing i.e. oversampling reduces the Power Spectral Density!!!!
WHY OVERSAMPLING? 2
37
๐ ๐๐๐ ๐ ๐ ๐
2๐ ๐
๐ ๐๐ท ๐๐๐ท๐ ๐๐๐ ๐ ๐พ ๐ ๐๐พ ๐ ๐โ ๐ ๐๐๐ ๐ ๐ ๐
๐ ๐
2๐พ
๐ ๐
2
a) b)
Itโs easy to see that for equal lowpass filters in a) and b) either analog or digital the still improves by a factor !
Easy analog filter design, reduced delay, re-configurability, Ok! Is that all? What about PQN power?
Letโs assume ideal brick-wall lowpass filters at for both a) and b) and consider the Signal-to-Noise Ratio :
a) ; b) โ improves by a factor !
Sampling Frequency Bandwidth
Actual : , ,