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

In the first part of this article, I showed the usage of the FFT (Fast Fourier Transform) in LTspice briefly, highlighted some details about the various settings affecting the quality of the FFT result and showed the effect of windowing functions, too. In this second part, I will introduce the Fourier series function in LTspice and show an interesting use case for analysis of power line harmonics based on measured current waveforms.

Fourier series

The Fourier series can be used to decompose and analyze periodic signals. It can be calculated in LTspice by adding the .four spice directive to the schematic before performing the transient simulation. The corresponding syntax (see LTspice Help):

.four <frequency> [Nharmonics] [Nperiods] <data trace1> [<data trace2> …]

The frequency parameter defines the fundamental frequency (the lowest frequency of interest). The optional parameter Nharmonics sets the number of harmonics being calculated (default: Nharmonics=9), while the Nperiods parameter determines the number of full signal periods used for the analysis from the end time of the simulation (default: Nperiods=1). The data trace names identify the signals to be transformed.

Figure 1 shows a simple test circuit with the necessary spice directives to perform the analysis. V1 provides a symmetrical triangle waveform to net SIG. The result can be read in the error log after running the simulation (use the CTRL+L hotkey to open it).

Figure 1. Fourier series test schematic

The waveform is plot in Figure 2, while Figure 3 shows the result of the Fourier series from the corresponding error log (use CTRL+L to invoke it).

Figure 2. Triangle wave test voltage
Figure 3. The Fourier series of the test voltage

The results are listed in a table with the parameters of the individual harmonics. The column Fourier Component shows the amplitude (peak!) of the particular sinusoid component with the given frequency, while the values normalized to the amplitude of the fundamental harmonic are also shown. Similarly, the absolute and relative phase values are also indicated. As we expect, the even harmonics are close to zero, while the amplitudes of the odd harmonics match well with the analytical values defined by the following expression:

Where A is the amplitude of the triangle wave. This results in A1=0.81057V, A3=0.09006, A5=0.0324V amplitudes for instance – just like what we got from the simulation above.

There are two different THD (Total Harmonic Distortion) values calculated and shown in the results above. Unfortunately, the LTspice Help does not provide any information about the two different THD values, but it is quite simple to figure it out based on the two known THD definitions:

1.

2.

Where Vn represents the RMS of the nth harmonic, and VRMS is the RMS of the waveform including all harmonics and noise.

The first definition considers the calculated harmonics only, and ignores the noise, resulting in a slightly lower THD, depending on the nature of the signal. The second definition however, considers all harmonics and noise in the calculation – therefore the name “THD+N”, indicating that the noise is included in this figure. Though the difference between the two THD values does not necessarily caused by the additive noise of the signal, but the lack of the higher order harmonics in the calculated Fourier series.

Analysis of power line harmonics in LTspice

We can use the Fourier series to analyze simulated signals as well as measured waveforms. An interesting use case is presented below.

When dealing with off-line PFC (Power Factor Correction AC/DC) and other power supplies, there are certain standards (the IEC 61000-3-2 for instance) calling for measurement and evaluation of the harmonics of the line current. A proper compliance test shall always be done with power line analyzers, providing very high dynamic range, high accuracy and correct integration time constants. In engineering practice however, it is quite useful to have a simple tool for power line harmonics analysis for pre-compliance testing during development.

For this purpose, it is possible to capture and save the current and voltage waveforms of the DUT with a digital oscilloscope and analyze them in LTspice. Figure 4 shows a measurement example of a PFC stage with load, where the AC input voltage and current waveforms were captured. The length of the captured data was 50ms. The line frequency was f=50Hz, thus the period time is T=20ms.

Figure 4. Measurement setup for AC line voltage and current waveform capture

The waveforms were saved in ASCII format in two separate text files and are imported in the simulation (Figure 5) by V1 and I1 PWL sources, respectively.

Figure 5. Test simulation for importing the measured waveforms

A simulation length of 40ms is set for the transient simulation (directive: .tran 40m) to ensure that there are exactly two line periods being simulated and plot. The Fourier series is calculated for both signals up to the 50th harmonic. We can run a simulation now to gather data from the Fourier series of the voltage waveform first. The imported waveforms appear in Figure 6. Now we can look up the phase angle of the fundamental component in the error log (Figure 7).

Figure 6. Measured AC line waveforms (red: line voltage, green: line current)
Figure 7. The Fourier series of the measured voltage waveform

As it can be seen from the table above, the phase of the fundamental harmonic is ϕ=-91.56°. Therefore, by applying a dt=91.56°/180°∙10ms=5.0867ms time delay in the transient simulation settings (Edit simulation command->”Time to start saving data” field), the voltage waveform can be adjusted to ensure its fundamental component has 0°phase angle – this will be the phase reference for the evaluation of the phase of the current harmonics. Thus, the modified simulation directive is: .tran 0 45.0867m 5.0867m. We can also add some measurement directives to calculate the RMS value of the measured waveforms as well as the apparent and real power levels (Figure 8). The time shifted waveforms are shown in Figure 9, while the final Fourier series and the results of the measurements statements are shown in Figure 10.

Figure 8. Test simulation with delay in the transient stimulus and additional measurement directives
Figure 9. Delayed transient waveforms
Figure 10. Final Fourier series and waveform measurement results

The DC component of the analyzed waveforms appear at the top of the Fourier component tables, indicating the offset of the respective measurements. It is possible to compensate the waveforms for these DC offsets before calculating the RMS values, but these offsets will hardly affect the accuracy if they are less than 1% with respect to the fundamental components. As it can be seen from the tables above, the line voltage is now aligned to the simulation timescale in such a way that the phase of its fundamental component is (almost) zero, allowing a direct and easy readout of the phase of the current components.

Comparison with the results of an AC power analyzer

A Voltech PM100 power analyzer was also used during the capture of the line voltage and current waveforms to provide a reference for comparison of the measurement results. Figure 11 shows the most important AC line parameters (RMS voltage, RMS current, apparent and real power, power factor, current and voltage THD) obtained directly from the power analyzer and from the LTspice analysis, respectively.

Figure 11. Comparison of the measured AC line parameters

The comparison of the measured current harmonics is shown in Figure 12. Note that the amplitude scale is logarithmic in order to enable a comparison over a high dynamic range.

Figure 12. Comparison of the measured current harmonics

The voltage and current THD values as well as the dominant current harmonic amplitudes are in excellent agreement, indicating the usefulness of the shown measurement and analysis method.

[1] Voltech PM100 User Manual

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

Using the Bode 100 with standard 10:1 probes

It is essential to have the right measurement instruments in an electronics laboratory if someone has the aim to work on a high level in electronics R&D.

When it comes to a potential purchase of measurement equipment however, a lot of us engineers suffer from the very limited budget available for investment in such professional tools – and this is quite usual even at the biggest, well prospering R&D companies as well as for individual entrepreneurs.

One of the most important measurement tools I have got in my lab – besides the high bandwidth, high speed digital storage oscilloscope – is the great Bode 100 Vector Network Analyzer (VNA), made by Omicron Lab (Figure 1). This “low-frequency” VNA is a really versatile instrument supporting various measurement types like: transmission/reflection measurement, gain/phase frequency response measurement and many different types of impedance measurement as well. Whether one has to analyze power supply stability or to characterize passive components or filter networks, the Bode 100 can be incredibly useful, especially in a power electronics lab.

Figure 1. Bode 100 Vector Network Analyzer with accessories

Considering the build quality of the instrument and the features of the control software, the Bode 100 VNA is fairly priced. In contrast to this, the dedicated 10:1 probes (Type: PML 111O, made by PMK) seem to be a bit overpriced to me. Since the Bode 100 has an input termination different from the usual scope input (as shown in Figure 2), regular 10:1 scope probes cannot be used to ensure proper voltage division ratio at DC.

Figure 2. Bode 100 receiver input (simplified) equivalent circuit

(*) C1 corrected 01/21/2022 – thanks to Florian Hämmerle 🙂 !

As it can be seen in this equivalent circuit, the VNA input is terminated by a 1M resistor after the DC blocking (or: AC coupling) capacitor, which prevents the usual 10:1 probes from working properly: C1 blocks the full measured DC voltage without any voltage division regardless of the nominal probe ratio, and only the AC component is being divided. (The dedicated PML 111O probe oveercomes this issue with built-in termination resistor). According to the technical specification of the instrument [1], the maximum input voltage is 50V, which is limited by the voltage rating of the AC coupling capacitor at the receiver inputs.

Measuring off-line Power Factor Correction (PFC) circuits and isolated power supplies often calls for control loop measurements at high-voltage nodes of the circuit (typically around 400V), thus these require at least 10:1 divider ratio from DC over the whole measurement frequency range. Some measurements may require a probe with even higher divider ratio (ie. 100:1).

There is a simple way to turn a regular 10:1 scope probe into a properly terminated 100:1 probe that is specifically suitable for the Bode 100. A simple circuit for this purpose is shown in Figure 3. Besides providing the proper DC termination, this circuit also ensures the DC blocking happens outside the VNA, making the test setup even more flexible (and robust) in terms of voltage rating.

Figure 3. Using standard 10:1 probe with additional termination circuit

The resulting “AC” divider ratio (assumption: the frequency of the measured signal is above the cutoff frequency of the high-pass filters formed by C4-R3 and by C2-R2, respectively):

So the used 10:1 probe has a 100:1 effective AC voltage measurement ratio with the additional termination, while the blocked DC voltage (measured across C4) is approximately 1/50 of the input DC component. R3 and R4 termination resistors can also be replaced by one resistor on the probe input of the circuit. Making the termination symmetrical has an advantage in implementation: the termination box does not need to have a dedicated direction, so the input and output ports are interchangeable.

It is important to note that the probe can be highly undercompensated with the shown termination resistors, causing a significantly higher gain above a few kHz (see Figure 5). The decreased value of the termination resistors shift the compensation pole upwards, altering the frequency response drastically. The unusual transfer characteristics caused by the undercompensation does not really matter in case of control loop measurements, since the ratio of the two receiver channels is being evaluated in this case. Thus, the only important factor is that the used two probes have to be well matched – this usually can be easily achieved in the 0Hz-10MHz range by the adjustable built-in compensation capacitors of regular 10:1 probes.

Clearly, it is quite simple to eliminate this effect by adding extra compensation capacitors in parallel to the termination resistors (Figure 4). The bode plot for a properly compensated probe can also be seen in Figure 5. The remaining deviation in the amplitude and phase response is reasonably small this way.

Figure 4. Improved termination circuit with additional compensation capacitance

Figure 5. Frequency response of the 10:1 probe with the additional termination circuit

This additional termination circuitry can be built in separate, small metal boxes with BNC connectors and can be inserted to be signal paths without modifying the probes. Such an implementation is shown in Figure 6 below.

10uF/63V rated film capacitors was used here. Note that it does not have to be high voltage rated, since the DC voltage gets already divided here properly. A low-inductance GND return path can be implemented by adding a copper strip next to the capacitor leads, soldered onto the GND joints of the two BNC connectors. One layer of insulator (tape) below the copper strip helps to avoid any short circuits.

Figure 6. The implemented termination boxes

Figure 7 shows a test done with Bode 100 using low-cost 10:1 probes with the shown modified termination. Both probes are connected directly to the source output of the VNA and the ratio of the two receiver channels is plot here, therefore, unity gain and zero phase are expected over the measurement frequency range. As it can be seen from the bode plot, the probes can be matched very well by adjusting the capacitive compensation of the probes.

Figure 7. Measured “unity gain” transfer characteristics with two modified probes

Finally, I highly recommend watching the Bode 100 review and teardown videos from EEVblog on Youtube, showing some interesting details about this VNA.

[1] Bode 100 Technical Data Sheet by Omicron Lab, 2021