Signal analysis in the frequency domain with LTspice – Part 1.

Updated on 29/01/2022 (**)

There are a few important points to be aware of when evaluating signals in the frequency domain in LTspice. In the first part of this article, I will highlight some details of the FFT function, while the second part will discuss the features of the Fourier series function (.four command) in LTspice.

FFT (Fast Fourier Transform)

The FFT with selectable windowing function is available from the plot window in LTspice (Plot Window-> Right click->View-> FFT)

Figure 1. FFT settings

The user can select:

  • the waveform for FFT analysis
  • the number of data points (I will call it N here)
  • the time range (T)
  • the number of points for binomial smoothing
  • the windowing function

FFT frequency resolution and span

The FFT frequency resolution (the FFT “bin size”) is inversely proportional to length of the time domain signal (T), thus, the longer the simulation data the better the frequency resolution: Δf=1/T. The amplitude spectrum is plot between fmin= Δf and fmax= Δf∙N/2 frequencies. With the default N=262.144=218 setting we get a frequency span of more than 5 decades.

For general use, I recommend the default settings for the number of data points, for the time range and for the binomial smoothing as well.

There are some simulation settings also affecting the quality of the FFT result. In order to demonstrate this, we will have a look at the FFT result of a pure sinewave first. The schematic of the first simulation is shown in Figure 2. V1 generates a 10kHz sinusoid signal with an output voltage of 1V RMS.

Figure 2. Generating sinusoid test signal

The length of the transient simulation is set to 1ms, the time domain waveform is shown in Figure 3, while Figure 4 shows the FFT plot with default settings (no windowing function is used here).

Figure 3. Sinusoid test signal in time domain
Figure 4. Sinusoid test signal in frequency domain (**)

The first thing to notice here is that the Fourier components are being scaled: we expect an amplitude of 1.414V at 10kHz, but the result shows exactly 0dBV (=1V) at the fundamental frequency. So instead of reflecting the amplitude, the displayed values in the FFT diagram correspond to the RMS value of the individual harmonics in LTspice. This seems to be a bit odd to me, since I would rather expect the amplitude (or even more precisely: the magnitude) to be plot in the FFT spectrum. In contrast to this, the Fourier series function (.four command) returns with the magnitude (and phase) values, as it will be shown later on.

FFT Noise Floor and SFDR

As it can be seen in the amplitude spectrum above, the noise floor is about -93dB -122dB, while there are clearly some spurs visible around 800 khz limiting the useful SFDR (Spurious Free Dynamic Range) at about 86dB 72dB (**). The appearing noise and spurs are essentially numerical artifacts caused by quantization errors. This noise floor and SFDR may or may not be good enough for the analysis of a certain signal of a simulated circuit, but there are various optional settings to improve the quality of the FFT result.

The first option is disabling the compression of the simulation data by putting the .option plotwinsize=0 spice directive in the schematic. Figure 5 shows the amplitude spectrum obtained by this setting: the noise floor is well reduced to about -110dB -167dB and the SFDR is increased to 100dB 105dB (**).

Figure 5. Sinusoid test signal in frequency domain with data compression disabled (**)

Should there be a need for an even lower noise floor (or lower spurs), the numerical accuracy can be further improved by adding the .option numdgt=7 directive and limiting the maximum timestep of the transient simulation. All the applied changes in the schematic are indicated in Figure 6 (a maximum timestep of 100ns is used in this example). A noise floor of about -193dB -250dB and an SFDR of 169dB 165dB (**) is obtained in the enhanced FFT spectrum (Figure 7).

Figure 6. Test circuit with modified simulator options
Figure 7. Sinusoid test signal in frequency domain
with disabled data compression & double precision & limited timestep

The achieved noise floor and SFDR values are summarized in Table 1 in order to have a better overview of the effect of the used optional settings.

Table 1. The effect of simulation options on the FFT performance (**)

FFT Windowing

It is also important to select a proper windowing function, since it determines the so-called spectral leakage among the frequency bins of the FFT result. For those less familiar with FFT windowing, here is short guidance to decide when to use them:

  • The FFT can be used without a windowing function (a.k.a. “rectangular windowing”):
    • If the analyzed signal is periodic (one distinct fundamental + its harmonics) and the simulation data contains exactly an integer number of periods (a.k.a. coherent sampling)
    • Or if the analyzed signal is periodic (one distinct fundamental + its harmonics) and the simulation data contains several periods of the lowest harmonic of interest (~10 periods minimum is a good starting point)
  • In all other cases (*), a windowing function shall be applied in order to reduce the spectral leakage between the side lobes. The most known windowing functions are: Bartlett, Hamming, Hann and Blackman-Harris with slightly different side lobe attenuation.

(*) for instance: aperiodic signals, stochastic signals (noise), sinusoid multitone signals with components close to each other, etc.

The circuit shown in Figure 8 is used to demonstrate the importance of applying a proper window function. V1 and V2 provide sinusoid voltages with the same amplitude (1V RMS) but at slightly different frequencies: fV1=10kHz, fV2=10.5kHz. The length of the transient simulation is set to T=1ms, therefore, the size of the FFT bin (so the resolution of the amplitude spectrum) is: Δf=1/T=1kHz.

Figure 8. Generating 10kHz and 10.5kHz sinusoid test signals

Figure 9 shows the result of the FFT with rectangular windowing (by selecting “none” at the FFT window settings) for both signals, while the same results with Hann windowing are shown in Figure 10. Clearly, the windowing makes no difference in case of the 10kHz signal (Sin_1, green curves): we see 0dB in both amplitude spectrums – that is because the periodic signal being transformed is sampled coherently. However, the 10.5kHz signal (Sin_2, blue curves) appears with different amplitudes: the FFT with rectangular window shows -4dB while the one with Hann indicates -1dB signal level. So, by a frequency offset of Δf/2 the lack of windowing causes a 3dB larger error in the amplitude reading, even with a pure sinusoid signal. The main lobe is somewhat wider and flatter in case of the Hann window – but it has a much steeper roll-off at the same time, so the side lobes are much smaller.

Figure 9. FFT of the test signals with rectangular windowing
Figure 10. FFT of the test signals with Hann windowing

Even though the effect of overlapping side lobes with more complex signals is out of the scope of this article, having a look at the frequency response of the applied filters can help to understand the importance of this phenomena, too. Figure 11 shows the frequency response of the rectangular and Hann windows, respectively (adjusted to Δf=1kHz bin size). It can be seen that the Hann window provides much higher attenuation of the side lobes from the third frequency bin (thus, causing less spectral leakage), while the main lobe (“passband”) is wider. Excessive spectral leakage can potentially hide a different signal of interest during the analysis.

Figure 11. The frequency response of the rectangular (light blue) and the Hann (red) window functions

For general spectral analysis with FFT, I recommend using a relatively long simulation data and the Hann windowing function. Should there be a need for a better amplitude accuracy and a somewhat better suppression of the side lobes, the Flat-Top window can be a good option.

With all of these settings, there is a great potential in LTspice to analyze the signals in the frequency domain with outstanding accuracy.

_______________________________________________________

(**) UPDATE 29/01/2022:

As someone pointed out, it can be challenging to reproduce exactly the same noise floor and SFDR numbers. Interestingly, the quantization noise, and thereforethe the noise floor and SFDR depend on the number of nets in the schematic (and may depend any other signals, forcing a smaller timestep!). I originally ran the simulations with a circuit containing some more nets and sources actually, the above schematic pictures were just cropped from a bigger schematic. So to be correct I recently updated Figure 4-5-7 to show the correct results when running the simulation with just one source as shown in the corresponding schematics.

In order to see the difference and figure out the worst-case with any options setting, add further 2…3 sinusoid sources with different frequencies before running the transient simulation. You will be also surprised by the differences 🙂

______________________________________________________

Further reading:

https://www.edn.com/windowing-functions-improve-fft-results-part-i/

https://www.edn.com/windowing-functions-improve-fft-results-part-ii/

https://training.ti.com/sites/default/files/docs/adcs-fast-fourier-transforms-and-windowing-presentation-quiz.pdf