ST AN2182 Application note

July 2007 Rev 1 1/18
18
AN2182
Application note
Filters using the ST10 DSP library
Introduction
The ST10F2xx family provides a 16-bit multiply and accumulate unit (MAC) allowing control-oriented
signal processing and filtering widely used in digital applications.
operations such as multiplication as we ll as two main filter functions , FIR (finite impulse response) and IIR
(infinite impulse response), mainly used in digital signal processing.
The first chapter of this application note describes a theoretical digital implementation of four different
filters:
Low-pass filter
High-pass filter
Passband filter
Cut-band filter
The method adopted for each filter is th e approximation of the ideal filter model by a FIR filter . This th eory
aims to compute the FIR’s coefficients by truncating the real signal with a known window.
The second chapter illustrates a practical implementation of a low-pass filter using the ST10 DSP library,
its results and its limitations.
www.st.com
Contents AN2182
2/18
Contents
1 ST10 DSP library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Digital filtering principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 Fourier transform of a sampled signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Linear filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Finite impulse response filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Low-pass filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 High-pass filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Passband filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6 Cutoff band filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7 Implementation example using the ST10 DSP library . . . . . . . . . . . . . . . 12
7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.2 Sampling frequency and FIR coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.3 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.3.1 Frequency response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.3.2 Phase response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
9 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
AN2182 ST10 DSP library
3/18

1 ST10 DSP library

The ST10 DSP free library is a set of arithmetic and signal processing functions based on the
ST10 MAC unit. These functions are callable from C and fully compatible with the Tasking
compiler.
This library manipulates signed integers coded on 16 or 32 bits. These integers represent
numbers belonging to the interval [–1, 1[. We name these formats: Q1.31 and Q1.15.
Table 1. Examples of integer representations
For a detailed description of the ST10 DSP libra ry, please refer to the application note AN1442
“Signal processing with ST10-DSP”.
–1 -0.5 -0.25 0 0.25 0.5
1 - 1/2
15
1 - 1/2
31
Q1.15 0xFFFF 0xC000 0xA000 0x0000 0x2000 0x4000 0x7FFF 0x7FFF
Q1.31
0xFFFF
FFFF
0xC000
0000
0xA0000
000
0x00000
000
0x20000
000
0x40000
000
0x7FFF
0000
0x7FFFFFFF
Digital filtering principles AN2182
4/18

2 Digital filtering principles

Assume a continuous signal x(t) (the complex form corresponds to the signal’s phase and
magnitude at the instant t) with a pass band B. Assume that this signal will be filtered using a
filter with a continuous impulse response h(t).
When digital processing has to be used, it is necessary to sample the input signal with a
frequency of F
s
= 1/T
s
(T
s
being the sampling period). The output signal is then reconstituted
from the samples obtained at the filter’s output.
Figure 1. Example of input and output signals
The Shannon theorem states that when sampling a signal at discrete intervals, the sampling
frequency F
s
should be greater than twice the highest frequency of the input signal.

2.1 Fourier transform of a sampled signal

Signals are converted from the time domain to the frequency domain usually through the
Fourier transf orm. With the Fo urier transf orm, the signal is conv erted to a magnitude and pha se
at each frequency.
The Fourier transform of the sampled signal x(k) has the following expression:
The time representation can be computed f rom the X(f) as follows:

2.2 Linear filtering

Using the notations defined in the previous section, the output signal y(n) is the convolution of
the input signal x(k) and the filter impulse response h(k) .
where x(n) = x(nT
s
), h(n – k) = h((n – k)T
s
) and y(n) = y(nT
s
).
Filter h
Input signal Output signal
Xf() xk()e
i2kπf
=
xk() Xf()e
i 2kπf
=
yn() hn k()xk()
hk() xk()()
n
==
AN2182 Digital filtering principles
5/18
The output signal frequency response is given by the following expression:
where H(f), X(f) and Y(f) are the respective Fourier transforms of h(k), x(k) and y(k).

2.3 Finite impulse response filters

The FIR (Finite Impulse Response) a re non-recu rsiv e filters , mean ing that the outp ut signal y( i)
is a linear combination of N input samples x(k) in the case of a N–1 order filte r. Its equation is
where a
k
are the FIR’s coefficients.
A FIR filter is characterized by its order and its coefficients and can be used to implement any
kinds of filters (low-pass, high-pass, pass-band or cutoff band).
Yf() Hf() Xf()=
yn() a
k
xn k()
k0=
N1
⎝⎠
⎜⎟
⎜⎟
⎛⎞
=
Low-pass filter AN2182
6/18

3 Low-pass filter

The aim of this section is to create a low-pass filter with a cutoff frequency F
c
and a gain G = 1,
by determining a FIR filter using the digital approach. The FIR coefficien ts correspond to h(n)
where h is its continuous time response and h(n) = h(nT
s
).
In the frequency domain, the ideal filter corresponding to these criteria has the following
response:
Figure 2. Ideal low-pass filter frequency response
This filter’s impulse response in the time domain is
This response is sampled with a rate F
s
= 1/T
s
(sampling frequency), so the discrete response
has the followi ng expression
The impact of sampling h(t) with a rate F
s
is a periodization of the analog signal spectrum
around F
s
and a gain of F
s
. In fact, the frequency response corresponding to the sampled
impulse response is
Therefore , t o obtain a gain o f 1, t he h
s
response filter should be divided by F
s
. Using equations
(1) and (2), the low-pass filter time response becomes:
The impulse response is a sinus cardinal (sinc) function centered at the origin.
F
c
-F
c
0
1
Frequency
Magnitude
ht() Hf()e
2πift
fd
2F
c
c2tF
c
()sin==
(1)
h
s
t() hnT
s
()δtnT
s
()
=
( 2)
H
s
f() F
s
Hf nF
s
()
=
h
s
t() 2
F
c
F
s
------ c 2 n F
c
T
s
()δtns()sin
=
(3)
Loading...
+ 12 hidden pages