Home 0101 Filt Math Pwr Filter manual Examples Useful Rants
LTwiki's homepage
Filter Pages and LTspice Goodies on LTwiki
The Filter is a collection of filters: analog passive (names marked with a terminating _LC), analog active, infinite impulse response (names marked with a terminating _IIR), and finite impulse response filters (several are listed, each have something the others don't), all grouped into a single library file, for easy access. The purpose was to make a universal filter that can be both analog and digital, which can be configured to be either allpass, lowpass, highpass, bandpass, or bandstop, that can replace the slow process of calculating, implementing and then using a (multiple stage) filter, when the purpose of the simulation is different, not to mention the need to repeat the steps whenever changes occur, a filter that can be used anywhere a filtering function is needed, be it a quick example, or a full-scale schematic, that's simple to use and reliable.

Table of contents:

  1. General information
    1. Frequency graphs
    2. Basic usage
  2. Analog passive filters
    1. Butterworth_LC
    2. Chebyshev_LC
    3. Examples
  3. Analog active filters
    1. Bessel
    2. Butterworth
    3. Chebyshev
    4. InvChebyshev
    5. Cauer
    6. Examples
  4. IIR filters
    1. Butterworth_IIR
    2. Chebyshev_IIR
    3. InvChebyshev_IIR
    4. Cauer_IIR
    5. Examples
  5. FIR filters
    1. FIR
    2. FIRx
    3. FIR2
    4. FIR_FS
    5. Examples
  6. Moving average filters
    1. MAFv
    2. RRS
    3. Examples
  7. Custom filters
    1. 3dBoct
    2. Examples
TOC / TOP

General information

Because it's a list of filters, when first placing the symbol there will be a lot of listed parameters, which may be confusing, but no filter in particular will use every one of them. Some will be common, some won't, but unused parameters can be safely deleted or added anytime, there are builtin defaults for each.

Similarly, not all pins are used, or even needed but, no matter what type of filter, the most basic usage means using pins IN, OUT, and GROUND; the rest have various other uses. The GROUND pin must be used at all times!

TOC / TOP

Frequency graphs

All filters (with a few exceptions) have two ways of setting the frequencies:
  1. Specify the corner frequencies through parameters fp1, fs1, fp2, and fs2. This is similarly to the way the frequency vectors are specified in Octave, and the default settings (green values in the graph below).
    • allpass: 0 < fp1 = fs1, fp2 = fs2 = 0
    • lowpass: fp1 < fs1, fp2 = fs2 = 0
    • highpass: fs1 < fp1, fp2 = fs2 = 0
    • bandpass: fs1 < fp1 < fp2 < fs2
    • bandstop: fp1 < fs1 < fs2 < fp2
  2. Specify the bandwidths and central frequency through BWp, BWs, and fc. Set these by first deleting the previous four (blue values in the graph below).
    • allpass: 0 < BWp = BWs, fc = 0
    • lowpass: BWp < BWs, fc = 0
    • highpass: BWs < BWp, fc = 0
    • bandpass: BWp < BWs, fc > 0
    • bandstop: BWs < BWp, fc > 0
Frequency graphs
TOC / TOP

Basic usage

With a few exceptions, there are two ways to start the configuration:
  1. Specify the passband and stopband frequencies and attenuations, and set the order to zero, which triggers its automatic calculation internally (f0 is for digital filters only):
    sigma nT Zin Zout
    Win Choice sim SH Norm
    (f0) fp1 fs1 fp2 fs2
    G Asc Ap As N=0
  2. Specify the order and the passband frequencies and attenuations, which results in the stopband frequencies and attenuations to be automatically determined based on whether they are less or greater than their passband counterparts, according to the graphs above:
    sigma nT Zin Zout
    Win Choice sim SH Norm
    (f0) fp1 fs1 fp2 fs2
    G Asc Ap As N>0

The same is valid for the alternate way of setting the frequencies.

TOC / TOP

Analog passive filters

There are two filters available: Butterworth and Chebyshev (type I). They are LC ladders built in Cauer's form, singly- or doubly-terminated ports, and they can form lowpass, highpass, bandpass, or bandstop configurations. Trying to configure them as allpass (fp1=fs1>0, fp2=fs2=0) will result in "undefined behaviour". Whether they start with an inductance or a capacitance, or with a series or shunt element, it's established based on user input (internally autoconfigured), as shown below:

( Zin≤Zout & Zin>0 ) ^
Zin==-1 ^ Zout==0
( Zin>Zout & Zout>0 ) ^
Zin==0
Series inductance as the first element
Shunt capacitance as the first element

The internal numbering of the elements doesn't consider the type of the element, L or C, only its position in the ladder.

Both filters use the same pins:

Butterworth_LC

Butterworth LC ladder
Zin=<-1,0,0+..∞> Ω Input impedance. There are three possible settings:
  • Zin=-1 ⇒ zero-impedance input (voltage source)
  • Zin=0 ⇒ high-impedance input (current source)
  • Zin>0{Zin}Ω
Zout=<0,0+..∞> Ω Output impedance. There are two possible settings:
  • Zout=0 ⇒ high-impedance output (floating)
  • Zout>0{Zout}Ω output
Only one of the impedances can be zero at a time!
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
As dB Stopband attenuation, default 40
Asc dB Frequency-scaling attenuation. If Asc=0, N>0 the passband is optimized. Default 3.0103
N=<0:1:32>
N=<0:2:64>
- Order of the filter, its value represents the order after the frequency transformations. For lowpass and highpass the maximum order is 32 and can take odd and even values. For bandpass and bandstop it's 64, but only even values are valid. If N=0 and Asc>0, the minimum order is determined based on the values of the frequencies and attenuations. Default 13
sim s Total .TRAN simulation time, default 1
Rpar, Rser Ω LTspice's specific for inductors and capacitors, common for both (i.e. setting Rser means inductors and capacitors, together, will have it set, same for Rpar), defaults <1g,0>
TOC / TOP

Chebyshev_LC

Chebyshev LC ladder
Zin=<-1,0,0+..∞> Ω Input impedance. There are three possible settings:
  • Zin=-1 ⇒ zero-impedance input (voltage source)
  • Zin=0 ⇒ high-impedance input (current source)
  • Zin>0{Zin}Ω
Zout=<0,0+..∞> Ω Output impedance. There are two possible settings:
  • Zout=0 ⇒ high-impedance output (floating)
  • Zout>0{Zout}Ω output
While it's possible to design even orders with equal terminating impedances, special considerations are still needed for the output impedance.
Only one of the impedances can be zero at a time!
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Ap dB Passband ripple. If Ap=0, N>0 the passband is optimized. Default 1
As dB Stopband attenuation. If As=0, N>0 the stopband is optimized. This is the same as As>0, N=0. Default 40
Asc dB Frequency-scaling attenuation. If Asc≤Ap, Ap will be considered. Default 3.0103
N=<0:1:32>
N=<0:2:64>
- Order of the filter, its value represents the order after the frequency transformations. For lowpass and highpass the maximum order is 32 and can take odd and even values. For bandpass and bandstop it's 64, but only even values are valid. If N=0 and Ap>0 or As>0, the minimum order is determined based on the values of the frequencies and attenuations. Default 13
sim s Total .TRAN simulation time, default 1
Rpar, Rser Ω LTspice's specific for inductors and capacitors, common for both (i.e. setting Rser means inductors and capacitors, together, will have it set, same for Rpar), defaults <1g,0>
TOC / TOP

Examples

Doubly-terminated port
Lowpass
Highpass
Bandpass
Bandstop
Singly-terminated port
High impedance (current source) input
Zero impedance (voltage source) input
Zero impedance (shorted) output
The test pins

Doubly-terminated port

Singly-terminated port. A 4th order Butterworth lowpass prototype will be shown for all three cases.

The test pins

This results in a 10th order bandstop, thus a 5th order lowpass prototype. Probing the voltage at pin 0.2 will reveal a staircase voltage with 5 steps: 1.146813, 1.3712126, 1.9750031, 1.3712126, 1.146813 (as read by the cursor). Since the impedances are equal, the first element is a series inductance thus, after the frequency transformations, it's a parallel LC.

TOC / TOP

Analog active filters

These are the five classical filter designs: Bessel, Butterworth, Chebyshev I & II, and Cauer/elliptic. Only all-pole filters can form allpass.

Bessel

Bessel
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Asc dB Frequency-scaling attenuation, absolute values only.
  • Asc=0 ⇒ normal 1/ωp delay design.
  • Asc>0 ⇒ corner frequencies will have this much attenuation.
Default 3.0103
N=<1:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. There is no automatic order calculation, therefore N must not be null. Default 13
G - Gain, linear, default 1
sim s Total .TRAN simulation time, default 1
Rpar Ω LTspice's specific for inductors and capacitors, default 1g
TOC / TOP

Butterworth

Butterworth
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
As dB Stopband attenuation, absolute values only, default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc=0, N>0 the passband is optimized. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
sim s Total .TRAN simulation time, default 1
Rpar Ω LTspice's specific for inductors and capacitors, default 1g
TOC / TOP

Chebyshev

Chebyshev
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Ap dB Passband ripple, absolute values only. If Ap=0, N>0 the passband is optimized. Default 1
As dB Stopband attenuation, absolute values only, default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc≤Ap, Ap is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, Ap>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
nT=<-1,0> - Tweak to mimic the response of a passive filter. Even order filters will have the gain at the corner frequencies:
  •  0G
  • -1G*10(-Ap/20)
sim s Total .TRAN simulation time, default 1
Rpar Ω LTspice's specific for inductors and capacitors, default 1g
TOC / TOP

InvChebyshev

Inverse Chebyshev
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
As dB Stopband attenuation, absolute values only. If As=0, Asc>0, N>0 the transition band is optimized. Default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc=0, As>0, N>0 the passband is optimized. If Asc≥As, As is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
sim s Total .TRAN simulation time, default 1
Rpar Ω LTspice's specific for inductors and capacitors, default 1g
TOC / TOP

Cauer

Cauer/elliptic
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Ap dB Passband ripple, absolute values only. If Ap=0, As>0, Asc>0, N>0 the passband is optimized. If Asc≥As, As is considered. Default 3.0103
As dB Stopband attenuation, absolute values only. If As=0, Asc>0, N>0 the transition band is optimized. Default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc≥As, As is considered. If Asc≤Ap, Ap is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, Ap>0, As>0, it determines the minimum order to meet specifications and optimizes the transition band. Default 13
G - Gain, linear, default 1
nT=<-1,0> - Tweak to mimic the response of a passive filter. Even order filters will have the gain at the corner frequencies:
  •  0G
  • -1G*10(-Ap/20)
sim s Total .TRAN simulation time, default 1
Rpar Ω LTspice's specific for inductors and capacitors, default 1g
TOC / TOP

Examples

Allpass
Lowpass
Highpass
Bandpass
Bandstop
TOC / TOP

Infinite Impulse Response

These are the bilinear transform versions of the analog counterparts: Butterworth, Chebyshev types I and II, and Cauer, so they inherit the same properties. They are implemented with built-in sampling clock and optional external synchronization. The delays are transmission-lines, so the filters behave as good as they do. There is no allpass, but all four filters support lowpass, highpass, bandpass, and bandstop. For bandpass and bandstop the matching of the frequencies at the higher end cannot be done, an implicit minor caveat from the bilinear transform.

Pin 0.4 (marked with a triangular arrow) allows for external synchronization, but even if connecting an external clock will override the internal one, it will not disable it; to avoid unnecessary slowdowns, set f0=< - external_clock_value > and SH=1. For example, if the external clock is 1024, then f0=-1024.

The test pins have the same function irrespective of the filter: pin 0.1 outputs the order (V in .TRAN, dB/deg in .AC), pin 0.2 and 0.3 output the numerator's and the denominator's terms (if sim>0).

The way the test pins work is a bit cumbersome. First, the maximum order is N=32. Second, the way the filters are implemented is by calculating the analog poles and zeroes, then applying the bilinear transform, then using spectral transformations. This means that what would be a 2nd order stage for a lowpass, or highpass, will become a 4th order for a bandpass, or bandstop:

Maximum order transfer function per stage

Suppose the simulation card is .TRAN 80m and sim=80m. The total simulation time will be divided into 80 steps (fixed internal number), thus 1ms/step. These steps will be groupped into 5 segments, each representing the maximum five possible terms of the transfer function, A0:4 for pin 0.2, or B0:4 for pin 0.3. Each segment will have 80/5=16 steps, representing the maximum number of stages. The terms will appear as this sequence at pin 0.2: {A0[1:16], A1[1:16], A2[1:16], A3[1:16], A4[1:16]}, similarly at pin 0.3. The step-values in the sequence will be, according the the above settings: A0[1] from 0 to 1ms, then A0[2] from 1ms to 2ms, then A0[3] from 2ms to 3ms, and so on until A0[16], then A1[1] will start from 16ms to 17ms, then A1[2] from 17ms to 18ms, etc. Similarly for pin 0.3.

This will be shown later but consider for example a 5th order lowpass. This means that there will be 3 2nd order stages, so the output of the test pins will have 3 step-values in the beginning representing A0[1:3], then a flat section which is to be ignored, until 16ms, where A1[1:3] are, then another section that is ignored, until 32ms, where A2[1:3] are, after which everything can be ignored since A3 and A4 (and their B counterparts) are only valid for bandpass and bandstop. The same for pin 0.3. The transfer function for the first stage is constructed from A0,1,2[1] and B0,1,2[1] (as shown in the transfer function above), then A0,1,2[2] and B0,1,2[2], and the last one with A0,1,2[3] and B0,1,2[3], which means that some value-chasing with the cursors will be needed, but it's for science...

In .TRAN there are a few ways to use the IIR filters:

  1. Continuous-time input signals. This implies either:
    1. No internal clock (SH=0) ⇒ the fastest response, continuous-time output, provided the input is harmonic (e.g. a sine). It's unrealistic, but useful for an "analog Hilbert transformer", for example.
    2. Sample&hold enabled (SH=1) ⇒ slower, sampled output, mimics a whole digital filter, with included ADC-DAC, but without the output analog filter.
  2. Sampled input:
    1. No clock, external or internal (SH=0) ⇒ there may be spurious spikes due to LTspice being an analog simulator and the way it treats fast edges through the transmission lines (used internally as z-1). This might be avoided with careful usage of input sampling (edges in particular).
    2. External sync (f0<0, SH=0) with a SINE source as the external sync (e.g. SINE(0.5 0.5 {f0} 0 0 -1)) ⇒ the timestep is smooth and the edges are not preserved, the output will be sampled, but not very pretty, and it tends to get even less so the longer the simulation. It will be faster than with a pulsed clock, though.
    3. External or internal sync, the normal way, the safest, but the slowest (particularly if the internal clock runs along the external one). To help speed things up a bit, a minor trick can be used: LTspice's SAMPLEHOLD is used for sampling with its CLK input, which means that the only requirement for sampling is the rising edge, which means that the clock can be set as a reverse sawtooth. This will only slow down the simulation around the fast edge, the only one that matters, and let the simulation fly in between.

Butterworth_IIR

Butterworth IIR
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
As dB Stopband attenuation, absolute values only, default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc=0, N>0 the passband is optimized. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
sim s Total .TRAN simulation time, default 1
tr s Rising edge for the internal clock, needs SH=1, default 1m/f0
td s Internal clock delay, default 0
TOC / TOP

Chebyshev_IIR

Chebyshev IIR
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Ap dB Passband ripple, absolute values only. If Ap=0, N>0 the passband is optimized. Default 1
As dB Stopband attenuation, absolute values only, default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc≤Ap, Ap is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, Ap>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
nT=<-1,0> - Tweak to mimic the response of a passive filter. Even order filters will have the gain at the corner frequencies:
  •  0G
  • -1G*10(-Ap/20)
sim s Total .TRAN simulation time, default 1
tr s Rising edge for the internal clock, needs SH=1, default 1m/f0
td s Internal clock delay, default 0
TOC / TOP

InvChebyshev_IIR

Inverse Chebyshev IIR
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
As dB Stopband attenuation, absolute values only. If As=0, Asc>0, N>0 the transition band is optimized. Default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc=0, As>0, N>0 the passband is optimized. If Asc≥As, As is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, As>0, it determines the minimum order to meet specifications. Default 13
G - Gain, linear, default 1
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
sim s Total .TRAN simulation time, default 1
tr s Rising edge for the internal clock, needs SH=1, default 1m/f0
td s Internal clock delay, default 0
TOC / TOP

Cauer_IIR

Cauer/elliptic IIR
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1k>
Ap dB Passband ripple, absolute values only. If Ap=0, As>0, Asc>0, N>0 the passband is optimized. If Asc≥As, As is considered. Default 3.0103
As dB Stopband attenuation, absolute values only. If As=0, Asc>0, N>0 the transition band is optimized. Default 40
Asc dB Frequency-scaling attenuation, absolute values only. If Asc≥As, As is considered. If Asc≤Ap, Ap is considered. Default 3.0103
N=<0:32> - Order of the filter. It represents the order of the lowpass prototype. For bandpass and bandstop, if N=5, it will actually be a 10th order. If N=0, Asc>0, Ap>0, As>0, it determines the minimum order to meet specifications and optimizes the transition band. Default 13
G - Gain, linear, default 1
nT=<-1,0> - Tweak to mimic the response of a passive filter. Even order filters will have the gain at the corner frequencies:
  •  0G
  • -1G*10(-Ap/20)
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
sim s Total .TRAN simulation time, default 1
tr s Rising edge for the internal clock, needs SH=1, default 1m/f0
td s Internal clock delay, default 0
TOC / TOP

Examples

Since these are just like their analog counterparts, the focus will be on what makes them apart.
Internal sampling on/off
External sync
The test pins
TOC / TOP

Finite impulse response

They are built with the same goals in mind as the IIRs (built-in clock, external sync), but they are separated into several versions, each with their own baggage: FIR holds the majority of the windows and functions and allows a maximum 256th order, FIRx is an extended version of FIR that allows a maximum 1024th order, FIR2 has only the computational-heavy Dolph-Chebyshev window and many of FIR's functions, and a maximum 256th order, while FIR_FS implements the frequency-sampling method with the same maximum order of 256 and all the windows from FIR.

All of them make use of all of the available pins, with minor functional differences. Below is shown the pinout for all four FIRs:

All FIRs

The functions that the FIRs perform are: basic moving average, windowed FIR, pulse shaping, differentiator, and Hilbert transformer, and all of them can be lowpass, highpass, bandpass, and bandstop, while FIR_FS is atypical since it allows for any frequency-domain magnitude specifications. The same .TRAN guidelines as for the IIRs apply here, as well.

The internal configuration is not restricted to symmetrical impulse responses, only, but in order to have anything else besides the already listed options, filter.sub needs to be edited by hand. One way to do it is to comment out the original impulse response function and add a custom one, for example:

.func hn(x) {table(x, ...)} ; where x=[0:N-1]

For the pulse-shaping filters, the setting of oversampling (OS), rolloff (β), and number of symbols (SPS) can be done in two ways (shown in the examples):

  1. The most visible way, but clumsy, is by using:
    • SPS = nT (think Number of symbols per period, T)
    • OS = nT*f0/(fp1 + fs1) = nT*f0/(BWp + BWs)
    • β = (fs1 - fp1)/(fs1 + fp1) = (BWs - BWp)/(BWs + BWp)
    • N = OS*SPS
  2. The hidden way: directly set nT (SPS), OS (OS), and beta (β), the last two parameters being hidden and used, internally, to calculate the above settings. When these parameters are set manually, the equations from the previous point will be ignored.

FIR

Win=<0:29> - Selects the window:
  1. rectangular (boxcar, Dirichlet) – default
  2. Bartlett (Fejér, end points are null)
  3. Bartlett-Hann
  4. Blackman
  5. Blackman-Harris (3 terms)
  6. Blackman-Harris (4 terms)
  7. Blackman-Nuttall
  8. Bohman
  9. Cauchy
  10. Connes
  11. exact Blackman
  12. exponential
  13. flat top
  14. gaussian (generic window)
  15. generic cosine
  16. Hamming
  17. Hann (von Hann, Hanning)
  18. Hann-Poisson
  19. hyperbolic cosine
  20. Kaiser
  21. Kaiser-Bessel (according to Wolfram)
  22. Lanczos
  23. Nuttall
  24. Parzen (exponential, de la Vallée-Poussin)
  25. Poisson
  26. power of cosine
  27. spline transition
  28. triangular (end points are not null)
  29. Tukey
  30. Welch
Func=<0:6> - Selects between the available functions:
  1. basic/windowed moving average
  2. windowed FIR (default)
  3. gaussian, pulse-shaping
  4. raised-cosine
  5. (square-)root raised-cosine
  6. differentiator
  7. Hilbert transformer
While it is possible to apply a window to the gaussian pulse-shaping, it's not recommended.
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
fp1, fs1, fp2, fs2 Hz Corner frequencies for the passband and stopband, defaults <500,400,2k,2.5k>
BWp, BWs, fc Hz Alternate frequency settings: passband bandwidth, stopband bandwidth, and center frequency, defaults are calculated based on the corner frequencies and, based on those, <1.5k,2.1k,1.3k>
As dB Stopband attenuation, absolute values only. Only used by these windows:
  • exponential
  • hyperbolic cosine
  • Kaiser
Default 60
N=<0:257> - Length of the filter. If N=0 the minimum order is determined based on:
  • Func=<0,1,5,6> ⇒ Kaiser's formula, for all windows
  • Func=<2,3,4>nT*f0/(fp1+fp2)
Default 33
G - Gain, linear, default 1
sigma - Factor for the parametric windows:
  • Cauchy
  • Connes
  • gaussian
  • Hann-Poisson
  • Lanczos
  • Poisson
  • power of cosine
  • spline transition
  • Tukey
  • Welch
  • (0..∞)
  • [1..∞)
  • (0..∞)
  • [0..∞)
  • [1:3]
  • [0..∞)
  • [0..∞)
  • [1:∞]
  • [0..1]
  • [1..∞)
Default 0.5
Norm=<0,1> - Enables or disables the gain normalization. This only applies for :
  • basic moving average (Func=0)
  • windowed FIRs (Func=1, lowpass and bandstop, only)
  • raised cosine and root-raised cosine (Func=<3,4>)
  • differentiator (Func=5)
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
nT=<0,1:∞> - Has two roles:
  1. Affects the end points of the Hann, Hann-Poisson, power of cosine, Blackman, and Nuttall windows:
    • 0 ⇒ null (default)
    • 1 ⇒ non-null
  2. Represents the number of symbols per period for the pulse-shaping windows.
Since having both non-null ends, nT=-1, and specifying the number of symbol per period, nT>0, cannot be done, windowing a pulse-shaping filter with a window from point a) can only be done by explicitely imposing the order, N>0, in which case the number of symbols per period is automatically determined.
sim s Total .TRAN simulation time, default 1
a0, a1, a2, a3, a4 - Terms for the generic cosine window, default <0.2, 0.4, 0.3, 53m, -3m>
tr s Rising edge for the internal clock, needs SH=1, default 1m/abs(f0)
td s Internal clock delay, default 0
TOC / TOP

FIRx

This is the expanded version of FIR, having ltline with lininterp instead of tline, and N=<0:1025>.
TOC / TOP

FIR2

TOC / TOP

FIR_FS

Win=<0:29> - Selects the window:
  1. rectangular (boxcar, Dirichlet) – default
  2. Bartlett (Fejér, end points are null)
  3. Bartlett-Hann
  4. Blackman
  5. Blackman-Harris (3 terms)
  6. Blackman-Harris (4 terms)
  7. Blackman-Nuttall
  8. Bohman
  9. Cauchy
  10. Connes
  11. exact Blackman
  12. exponential
  13. flat top
  14. gaussian (generic window)
  15. generic cosine
  16. Hamming
  17. Hann (von Hann, Hanning)
  18. Hann-Poisson
  19. hyperbolic cosine
  20. Kaiser
  21. Kaiser-Bessel (according to Wolfram)
  22. Lanczos
  23. Nuttall
  24. Parzen (exponential, de la Vallée-Poussin)
  25. Poisson
  26. power of cosine
  27. rectangular (replaces spline transition)
  28. triangular (end points are not null)
  29. Tukey
  30. Welch
f0 Hz Sampling frequency, set negative for external synchronization, default 5k
As dB Stopband attenuation, absolute values only. Only used by these windows:
  • Kaiser
  • exponential
  • hyperbolic cosine
Default 60
N=<1:257> - Length of the filter, default 33
G - Gain, linear, default 1
sigma - Factor for the parametric windows:
  • Cauchy
  • Connes
  • gaussian
  • Hann-Poisson
  • Lanczos
  • Poisson
  • power of cosine
  • spline transition
  • Tukey
  • Welch
  • (0..∞)
  • [1..∞)
  • (0..∞)
  • [0..∞)
  • [1:3]
  • [0..∞)
  • [0..∞)
  • [1:∞]
  • [0..1]
  • [1..∞)
Default 0.5
SH=<0,1> - Affects the internal sample&hold:
  • 0 ⇒ disabled
  • 1 ⇒ enabled (default)
Enabling SH disables .AC analysis.
nT=<0,1> - Sets the sampling method:
  • 0 ⇒ even (default)
  • 1 ⇒ odd
sim s Total .TRAN simulation time, default 1
a0, a1, a2, a3, a4 - Terms for the generic cosine window, default <0.2, 0.4, 0.3, 53m, -3m>
tr s Rising edge for the internal clock, needs SH=1, default 1m/abs(f0)
td s Internal clock delay, default 0
TOC / TOP

Examples

The IIR examples apply here, as well, so the focus will be on the qualities that set the FIRs apart from the rest.
Func=0
Basic moving average
Func=1
Lowpass
Highpass
Bandpass
Bandstop
Func=<2,3,4>
Gaussian pulse-shaping
Raised cosine
(Square-)root raised cosine
Func=<5,6>
Differentiator
Hilbert transformer
Frequency sampling
Interpolated FIR
The test pins

Func=0

Func=1

Func=<2,3,4>

All use the same requirements: 4x oversampling ratio (OSR), 0.22 rolloff (β), and ±6 symbols (nsym), 3.84MHz sampling frequency, no window, unnormalized gain.

Func=<5,6>

Interpolated FIR

It needs UpDnSpl. Optional, SampledSource. This is a comparison between an IFIR and normal FIR with requirements: minimum order for a Kaiser lowpass with band edges [0.2Hz, 0.22Hz], 2Hz sampling frequency, and 80dB attenuation. The rate is set through the help of the parameter Rate.

If a single FIR is used, the resulting order is 502. Using a two-stage IFIR, the resulting orders will be:

  • 2x ⇒ 251 downsampler and 18 upsampler
  • 3x ⇒ 168 downsampler and 41 upsampler
  • 4x ⇒ 126 downsampler and 126 upsampler
  • IFIR:
    FIR (downsampler)
    sigma nT Zin Zout
    Win=19 Func=1 sim SH=<0,1> Norm=1
    f0={-2/Rate} fp1=0.2 fs1=0.22 fp2=0 fs2=0
    G=1 Asc Ap As=80 N=0
    FIR (upsampler)
    sigma nT Zin Zout
    Win=19 Func=1 sim SH=<0,1> Norm=1
    f0={-2} fp1=0.2 fs1={2/Rate-0.22} fp2=0 fs2=0
    G={Rate} Asc Ap As=80 N=0
  • Normal FIR:
    FIRx
    sigma nT Zin Zout
    Win=19 Func=1 sim SH=<0,1> Norm=1
    f0=-2 fp1=0.2 fs1=0.22 fp2=0 fs2=0
    G=1 Asc Ap As=80 N=0

Frequency sampling

Using the readily available and uncommented example of an inverse sinc filter with a Hamming window. The parameters are freq (cutoff frequency), fsinc (inverse sinc frequency factor), and power (inverse sinc power).
FIR_FS
sigma nT=<0,1> Zin Zout
Win=15 Func=1 sim SH=<0,1> Norm=1
f0=10k fp1 fs1 fp2 fs2
G=1 Asc Ap As N=<64,65>

The test pins

They work similarly to the rest of the filters (see IIRs, or LC filters, for example). If sim is set to match the .TRAN card, the values will fill the entire timespan. The only differences between the frequency sampling and the rest of the FIRs is that the first will output the FIR type, the frequency-domain formula, and the impulse response, and the others will output the order, the weights, and the impulse response.
TOC / TOP

Moving average filters

These emulate the digital versions of a moving average and a running recursive sum. There are no test pins.

MAFv

Moving average, variale window
f0 Hz Inverse of the period of the sliding window, default 1k
G - Gain, linear, default 1
Rpar Ω LTspice's specific for capacitors, default 1g
lim V Internal limits to avoid clipping, default 1g
TOC / TOP

RRS

Running recursive sum
f0 Hz Inverse of the period of the discrete integrator, default 1k
G - Gain, linear, default 1
N - Number of samples per period, default 10
TOC / TOP

Examples

Variable moving average
Running recursive sum
TOC / TOP

Custom filters

For now a 3dB/octave approximation made with series RC cells, adjustable-spaced.

3dBoct

3dB/octave
fp1 Hz Corner frequency, default 100
BWp Hz Alternate frequency settings: passband bandwidth, default fp1
N=<0:1:32> - Number of series RC cells, default 32
sigma - Makes the response around the corner frequency smoother or sharper, default 1
nT - Sets the distance between the RC cells along the spectrum, and it's the base for the power of two, (2+nT)n, default 0
Rpar Ω LTspice's specific for capacitors, default 1G
TOC / TOP

Examples

  1. This example emulates a cheap audio pink noise filter for the range of <20Hz..20kHz>, with 5 RC cells spaced every 3x frequency. Since the filter is configured to work as a lowpass, the corner frequency should be set a decade earlier and the gain 10x the desired one. For this case, f=20Hz/10=2Hz and G=1*10=10. The default spacing is octave-based, so to make it 3x set nT=1 to have (2+nT)n=3n. Adjust sigma and fp1 (or BWp) to fit the needs. Set the analysis to .ac dec 100 2 2meg to view the response.
    3dBoct
    sigma=1 nT=1 Zin Zout
    Win Func sim SH Norm
    f0 fp1=2 fs1 fp2 fs2
    G=10 Asc Ap As N=5

    Due to the influence of sigma and nT, the corner frequency is shifted, so to correct it set fp1=1. For a better fidelity, set a higher N and lower (minimum -1) nT.

TOC / TOP