Two people exercising on yoga mats to increase flexibility.

Digital Filters in LTspice: A More Flexible FIR Model Part 3 of 3

Continuing our journey with FIR filter models in LTspice, I’ll take a deeper dive into .AC and .NOISE measurements, using an alternative FIR model to demonstrate measurements that can be made to verify two different modeling techniques are equivalent.

In my February blog post, I introduced some blocks that can model a simple FIR filter in LTspice.  In April, I explored combining that digital filter model with analog circuit elements, and demonstrated how to make simple observations with both .AC and .NOISE analyses.

A More Flexible FIR Implementation in LTspice

Recall our initial FIR implementation was an average of consecutive samples:

y\left[n\right]=\frac{1}{M}\sum_{j=0}^{M-1}x\left[n-j\right]

where M is the number of samples.  If we expand the summation for an example of averaging three samples:

y\left[n\right]=\frac{x\left[n\right]+x\left[n-1\right]+x\left[n-2\right]}{3 }

Chapter 15 of The Scientist & Engineer's Guide to Digital Signal Processing shows an alternative mathematical implementation on page 283 that uses recursion.  My creative interpretation of that equation is:

y\left[n\right]=y\left[n-1\right]+\frac{x\left[n\right]-x\left[n-M\right]}{M}

where M is still the number of samples to average.  The output sample (y[n]) is equal to the previous output sample (y[n-1]), with the current input sample added on (x[n]), and the last input sample popped off (x[n-M]).

To implement a recursive FIR, we need two new model blocks: a delay-by-N block, and an adder block adding three signals.  These are minor variations of the blocks introduced in February’s blog post, allowing us to build the functionality we need with a clean schematic.

 Two Implementations of an FIR Filter Model in LTspice

Figure 1: Two Implementations of an FIR Filter Model in LTspice

Let’s prove this implementation is equivalent to the first before exploring the benefits of the recursive implementation.

Comparing the AC Response of Each Filter

To explore this example, open the FIR Filter Implementations.asc file in the attached .zip file. For LTspice to find all the necessary files, you will need to unzip the .zip file before opening the schematic file.

FIR-Filters-Part-3.zip

Select Simulate -> Run/Pause from the menu to run the AC simulation specified in the .AC directive on the schematic.  Figure 2 shows both inputs (top pane) and outputs (bottom pane) overlaid on each other.

 Frequency Response at the Inputs and Outputs of Each FIR Filter Model

Figure 2: Frequency Response at the Inputs and Outputs of Each FIR Filter Model

This allows us to quickly observe that the AC responses of these filters are identical.  Overlaying results for .NOISE simulations is not nearly as straightforward; but I’ll show you a trick…

Using .STEP to Observe Noise Results at Multiple Nodes

Shift-click on the active .AC directive to comment it out.  Right-click on the .STEP directive to bring up the text editor (Figure 3).

 Text Block of Multiple Directives: Converting from Comment to Active Directive

Figure 3: Text Block of Multiple Directives: Converting from Comment to Active Directive

This text block contains multiple directives that can be commented/uncommented as a group.  Click on the SPICE directive radio button to convert this text from a comment to an active set of directives and click OK. Run the simulation.

Now we need to get creative to view the results.  Type A to add a trace to the plot, and select v(onoise).  Once the waveforms are plotted, right-click on the waveform window and select Notes & Annotations -> Annotate Steps, and place the step legend on the waveform window (Figure 4).  Visit the blog post on using .STEP and .MEAS directive in .NOISE simulations to review some of the basic concepts of using the .STEP directive.

 Stepping Through Multiple Output Nodes in a .NOISE Simulation

Figure 4: Stepping Through Multiple Output Nodes in a .NOISE Simulation

Right-click on the plot and select View -> Select Steps.  Use this dialog to control which noise results are plotted.

 Selecting which .STEP Results are Plotted

Figure 5: Selecting which .STEP Results are Plotted

In this example, I’m using the .STEP directive to step through output nodes in my noise simulation:

.step param n list 0 1 2 3
.param noise_outnode=select(n, "INA", "OUTA", "INB", "OUTB")

In the first step (n=0), I’m examining the noise at the INA node: the noise generated by R1 and shaped by the filter formed by R1 and C1.  In the second step (n=1), I’m examining the noise at the OUTA node; the noise that is further shaped by the digital filter. 

Using .MEAS to Automate Measurements

Right-click on the .MEAS directives to bring up the text editor (Figure 6).  Click on the SPICE directive radio button to convert this text from a comment to an active set of directives and click OK. Run the simulation.

 .MEAS Directives to Measure Integrated Noise for Each .STEP Simulation

Figure 6: .MEAS Directives to Measure Integrated Noise for Each .STEP Simulation

Click on the schematic to ensure it is the active window, and select View -> SPICE Output Log (Figure 7).  Here we can see the integrated noise at INA (n=0), OUTA (n=1), INB (n=2), and OUTB (n=3).

 SPICE Output Log with Integrated Noise Measurements

Figure 7: SPICE Output Log with Integrated Noise Measurements

I’ve used three measurements to verify that these two filters behave identically: inspection of .AC waveforms, inspection of .NOISE waveforms, and automated .MEAS measurements of .NOISE simulation results.

What’s the advantage of using the recursive implementation?  Look at how easy it is to change the number of averaged samples from three to 50:

 Recursive FIR Averaging 50 Samples

Figure 8: Recursive FIR Averaging 50 Samples

Conclusion

These model blocks obviously don’t capture every aspect of a digital filter.  But they are simple and efficient models that you can use to understand the overall signal and noise response of your combined analog circuitry and digital post-processing.

Throughout this three-part series, we've journeyed from basic FIR building blocks to clever LTspice measurement techniques that let you confidently validate your mixed-signal designs. You now have the tools to model digital signal processing in LTspice, seamlessly integrate it with analog circuitry, and rigorously verify your implementations using AC analysis, noise simulation, and automated measurements.

Read all the blogs in LTspice Digital Filters series.