← |
↑ |
☜ |
⌂ |
V. FIR filters - Examples |
→ |
Note: Do not save the schematics after usage because they may be used in later examples.
Note: Opening the schematics from the links is best done with a Click+Drag
over an existing opened instance of LTspice.
While the order can be internally determined if
N=0
, it's not the recommended way to do it for other windows than
Kaiser,
exponential,
hyperbolic cosine or
Dolph-Chebyshev. The same
notes and
golden rule apply here, as well.
- Even if
Win
is listed as a parameter, its only purpose is to ensure unity weights, which means the only setting for it is Win=1
.
- In the same manner,
Choice
's only "choice" is 0
, which is selecting the moving average function.
- The Filter already has two moving average at the end of the list, but the difference between them is that here it's implementated with delays, sums and weights, while the others are analog approaches.
Following the example in the
table, a
moving average is configured with only these parameters:
SH, f0, G
and
N
, so the final configuration looks like this:
Win=1 Choice=0 sim=x test=x SH=0 Fact=1
f0=2
G=1 N=129
sim
and test
here are quite redundant since the weights are all 1
and the coefficients are all 1/N
. Fact≠1
can also be used, has an impact on the final result, but it's pointless.
The time domain shows an averaged inverted cosine with DC.
SH
allows continuous time signal at the output (
SH=0
), or sampled (
SH=1
), user's choice. This goes against the
golden rule, but can be regarded as a small useful cheat.
According to the
table, there are fixed and parametric windows, the last ones being a function of
sigma
or
As
(or both, for the
hyperbolic cosine exception).
- Low-pass
Using a fixed window, a
129
taps
Hann window
LP, with
ωc=π/4
, at
2Hz
sampling frequency and unity gain. The
graphs show the conditions for a
LP. Since there is no specified transition width, all there is to do is to make sure the values for
BWp
and
BWs
satisfy the above condition:
π/4=0.25Hz
⇒
(BWp+BWs)/2=0.25
; the values of
0.2
and
0.3
are chosen.
nT
sets both unnormalized gain (nT=-1
) and the values of the multipliers at the ends of the window (nT=1
), so having both is impossible. Gain normalization is for nT≥0
so, since the Hann window has null taps, nT=1
(it can be .stepped
). In rest, this is a frequency analysis, so SH=0
and it's a normal filter, Fact=1
. The parameters to set are these:
nT=1
Win=12 Choice=1 sim=x test=x SH=0 Fact=1
f0=2 fc=0 BWp=0.2 BWs=0.3
G=1 N=129
The time domain analysis is for a step response.
High-pass
The parametric windows as a function of sigma
provide a bit more flexibility in design. A generic Gaussian window for the same conditions as above, only made as a HP:
sigma={sigma} nT=1
Win=25 Choice=1 sim=x test=x SH=0 Fact=1
f0=2 fc=0 BWp=0.3 BWs=0.2
G=1 N=129
The
.step
line has a list of parameters which show that, even if the
table lists the values for
sigma
as ranging from
<+0..∞>
, the practical values are different; in short, the designer's common sense should be the limit. The same applies to the others.
Band-pass
The windows as a function of
As
are the most flexible.
Kaiser is chosen for a
192kHz
sampling frequency,
24kHz
central frequency, pass-band of
20kHz@-6dB
,
4kHz
transistion width and
-80dB
in the stop-band. Let the order be internally determined. According to the
graphs:
BWp = ωpb-ωtw
BWs = BWp+2*ωtw
and so, the parameters are these:
Win=26 Choice=1 sim=x test=x SH=0 Fact=1
f0=192k fc=24k BWp=16k BWs=24k
G=1 As=80 N=0
Band-stop
Choosing Win=29
selects the hyperbolic cosine window which allows for both As
and sigma
as variables: the former sets the stop-band attenuation, while the latter is the power of the window's function in time-domain: hyperbolicCos(x)σ
. This one is the only exception.
With Kaiser's order determination, the same values as before only reversed BWp
↔ BWs
and Win=29
.
The result is that of a
BP. The reason: pin
0.1
shows
241V
⇒ type
II. Because of the way the filter is
built, internally, the only valid responses for type
II are
LP, BP (i.e. no zero sample @
π/2). The solution is to either increase/decrease the order or adjust the frequency/attenuation constraints.
Easily achieved as long as:
- it's configured to be a LP
ωc=π/k, k≥2
, integer
- it's a type I and
N/2=odd
An example with FIR2 for the 4th
band with -60dB
attenuation:
Choice=1 sim=x test=x SH=0 Fact=1
f0=2 fc=0 BWp=0.2 BWs=0.3
G=1 As=60 N=67
Which is similar to the LP example with the Hann window.
This
example is used for comparison, with the same parameters but adapted to a
FIR. The pass-band has been tweaked to have ~
-3dB@5kHz
(matching the
IIR example) and the gain is the same
4⋅1.4142
to aid in the
.TRAN
simulation. In addition, a
Kaiser window (for
N=0
) and unnormlized gain:
nT=-1
Win=26 Choice=1 sim=x test=x SH=0 Fact=1
f0=44.1k fc=0 BWp=4295 BWs=6025
G=-4*1.4142 As=120 N=0
The negative gain is to better compare the output to the analog signal in .TRAN
. SH=1
is mandatory for time domain analysis of interpolation/decimation.
Using normalized frequences (Nyquist=1), L=4, ωp=0.1
and ωs=0.12
, a comparison with an exponential window between a normal FIR:
sigma=1 nT=0
Win=28 Choice=1 sim=x test=x SH=1 Fact=1
f0=-2 fc=0 BWp=0.1 BWs=0.12
G=1 As=80 N=0
...and a two stage IFIR:
sigma=1 nT=0
Win=28 Choice=1 sim=x test=x SH=0 Fact=-4
f0=-2 fc=0 BWp=0.1*4 BWs=0.12*4
G=1 As=80 N=0
sigma=1 nT=0
Win=28 Choice=1 sim=x test=x SH=1 Fact=1
f0=-2 fc=0 BWp=0.1 BWs=1/L-0.12
G=1 As=80 N=0
The trick here is using
SH=0
with
Fact=-L
(or
L
for interpolation), which is one exception for the
golden rule. The explanation: decimation, from
LTspice's point of view, it's better with one
S&H at the output rather than with one on each branch;
SH=<0,1>
disables or enables the
S&H, but the delays are still
z-L, which is exactly what's needed for the 1st stage (here) of the
IFIR. Still, care should be taken that the input is properly sampled because if
SH=0
,
external synchronization is not possible.
The order is automatically determined after Kaiser's formula, which gives a very close approximation for this type of window (and the hyperbolic cosine). The negative f0
is for external sync (only one clock instead of another two, internally; faster). In .AC
, plotting V(b)/V(a) will show the response of the 2nd stage, only. It can be seen that the exponential window doesn't exactly meet the specifications, but here it's used for the sake of exemplification; if exact matching is desired, the Kaiser window (Win=26
) will do. The .TRAN
sweep is from 0.01 to 0.6, encompassing the aliasing region of the 1st stage of the IFIR.
The same example will be used for all three: SPS=4
(the oversampling factor, or samples per second), β=0.22
(the roll-off factor − for raised cosine and root raised cosine − or the BT
product − for the Gaussian), a slightly exaggerated nr_sym=±12
(the number of symbol periods, or samples, per second) and 3.84MHz
sampling frequency.
The math for determining the parameters is common to all:
BWp = f0/(2⋅SPS)⋅(1-β) = 3.84Meg/(2⋅4)⋅(1-0.22) = 374.4k
BWp = f0/(2⋅SPS)⋅(1+β) = 3.84Meg/(2⋅4)⋅(1+0.22) = 585.6k
nT = 2⋅nr_sym = 2⋅12 = 24
which, considering a rectangular window and unity gain, give the following parameters:
nT=24
Win=1 Choice={Choice} sim=x test=x SH=0 Fact=1
f0=3.84Meg fc=0 BWp=374.4k BWs=585.6k
G=1 N=0
where {Choice}
is externally defined as a .param
and sets the pulse-shaping window according to the values ennumerated in the table. The unscaled gain for the pulse-shaping windows can be verified with nT=-1
.
While Choice=2
and Win>1
is possible, it isn't done in practice so it should be avoided; the other two allow windowing, though. E.g.: raised cosine with Dolph-Chebyshev having an arbitrary -40dB
attenuation in the stop-band; FIR2 needs to be used:
nT=24
Choice=3 sim=x test=x SH=0 Fact=1
f0=3.84Meg fc=0 BWp=374.4k BWs=585.6k
G=1 As=40 N=0
If β
needs to be .stepped
for raised cosine or root raised cosine, the parameters can be changed like this:
f0={f0} BWp={f0/2/SPS*(1-beta)} BWs={f0/2/SPS*(1+beta)}
and the .param
and .step
statements should be changed/added like this (left as an exercise):
.param f0=3840k SPS=4 beta=0.2
.step param beta 0 1 0.2
- Differentiator...
...until 0dB@π/2
and a "don't care" transition band given by a 64
tap type IV. The sampling frequency is 192kHz
:
nT=0 a0=0.48 a1=0.5 a2=0.08 a3=0 a4=0
Win=11 Choice=5 sim=x test=x SH=0 Fact=1
f0=192k fc=0 BWp=48k BWs=60k
G=1 N=64
nT=0
is because of the imposed gain @
ωc
and the window chosen is the
general cosine (which has the terms
hidden):
a[0:4]=[0.42, 0.5, 0.08, 0, 0]
, making it a
Blackman. The same could have been achieved by letting
Win=16
, but this is for the sake of the example (
Zin
and
Zout
, unused, were deleted to make room, a practice not encouraged).
- Hilbert transformer
To reuse the schematic, Choice=6
.
The results of both can be viewed in
.AC
or
.TRAN
. For the time domain simulation, both digital and analog signals can be used with the same
cheat.
Using FIR_FS isn't quite as straightforward as the other ones:
- First, filter.sub must be opened with a text editor.
- Once inside, a search for "
.subckt FIR_FS
" will lead to the subcircuit of the FIR_FS.
- Scrolling down a few lines there is a function defined as
.func fspl(x) {...}
and a few other, similar, but commented out (these are examples). Considering the description, the .func
can now be expressed in an LTspice-friendly manner.
For this case, the "linear phase Butterworth" can be uncommented while commenting out the default
fspl(x)
. From here on, the
windows can be applied with
Win
, the
types can be chosen through
Choice
and odd/even sampling through
nT
:
sigma=x nT={nT}
Win=1 Choice=1 sim=x test=x SH=0
f0=2
N={N}
Here, N
and nT
are externally defined to allow .stepping
their values. The transient step response can also be viewed if the cards are switched between themselves.
Any schematic so far can be reused to view the coefficients, h[n], and the weights, w[n], in .TRAN
. The schematic reused here can also show the differences between nT=0
and nT=1
for the Hann window.
©Vlad, 2008 - 2015