## Managing PWM Waveforms, Part 1 - Data Reduction

This is the first part of a three-part series on special handling of PWM waveforms. The first two parts deal with the large amount of data involved. The last part deals with precise characterization in the presence of switching cycle “noise.” I am honored to post this article, which was created by one of our talented community members, a modeling and simulation expert and my friend, Norm Elias:

Large amounts of data, i.e., large numbers of time points, result from simulating milliseconds of switch-mode operation with microseconds per switching cycle. Even if all of your software applications can handle the large files, those files can be an inconvenience. Fortunately, there is an easy way to reduce the data by sampling the time points. I’ll use the series R-L-C design in Figure 1 to describe and demonstrate the data reduction procedure.

Figure 1 Introductory Example, Series Resonant Circuit

This design can be found at: https://www.systemvision.com/design/waveform-sampling

In a nutshell, I’m describing a pre-process simulate/post-process procedure. The pre-process step adds a sampling strobe to the original design. The post-processing step is a short series of Excel edits using the sawtooth strobe to sample the waveforms. In  Figure 1, the strobe is supplied by a voltage pulse source named Samplgen. You configure it to produce a sawtooth waveform as shown in Figure 2. The sawtooth generates uniformly spaced sampling times starting at t=0. Negative going pulses make it easy to locate the strobe samples.

Figure 2 Sampling Voltage

In this example, I’m simulating the R-L-C response to a 50% duty cycle pulse. When the simulation is completed, I download all waveforms of interest plus the sampling sawtooth as shown in Figure 3. To open the waveforms in Excel, I click the box that appears at the lower left of my screen and select Open as shown in Figure 3.

Figure 3 Simulate and Export Waveforms to Excel

The post-processing in Excel is a one-time event involving the full set of original time points. It’s a cookbook procedure that follows this recipe:

• Copy all waveforms into a single spreadsheet
• Optional: Reduce the header to one row
• Sort all rows by the sawtooth (viz., v_sample), largest to smallest
• Scroll down to the first row with v_sample < 0.0
• Delete all rows from there down
• Sort all rows by the time value, Smallest to Largest
• Save the result

Figure 4 compares the V_pls_out waveform before and after this post-processing step. The Excel operations reduce the table from 6,901 time points to 201--a 97% reduction.

A) 6,901 Time Points                                                                                        B) 201 Samples

Figure 4 Sample the Waveforms in Excel

The next thing I’m going to do is to put this waveform right back into the simulation so I can compare the 201 time point representation to the original 6,901 time points of V_pls_out. The same technique can be used in a development project to compare revised designs or to analyze a variety of signal processing schemes. The key ingredient is the voltage source named v_reduced in Figure 1. This is a voltage function generator, which I selected from the panel of Analog Electronics components. I’ve selected the table mode as shown in Figure 5. To place the 201 time and V_pls_out, I copy the values in Excel, open the properties menu of the function generator, select any cell after the first row, and paste the entire waveform with a single click. When I run the simulation, the function generator will output the saved V_pls_out waveform.

Figure 5 Copy and Paste Into a Function Generator

Figure 6 compares the 201 point waveform to the original simulation result. I’ve simulated two complete cycles of the V_pls_out pulse. With the “Periodic” box checked in the function generator menu (See Figure 5), V_reduced repeats the pulse in the second cycle. The first cycle of V_reduced appears to match the original V_pls_out waveform exactly until you zoom in and look closely. The magnified view in Figure 6 shows V_reduced as a very good piecewise linear approximation that matches exactly at the sampling points.

Figure 6 Compare Sampled (Reduced) and Original Waveforms

Sampling theory says that a waveform limited to a bandwidth of f ≤ fmax can be regenerated exactly at all time points if it is sampled at a uniform rate equal to or greater than twice fmax, i.e. at fsmp (= 1/Tsmp) ≥ 2*fmax . For the R-L-C example, a frequency analysis shows that V_pls_out is 20dB down at fmax = 12 KHz. For fsmp = 2*fmax = 24 KHz, the 4ms pulse can be regenerated from as few as 24 KHz * 4ms = 96 samples.

The 201 samples used here are more than enough. However, a PWM waveform, such as that sketched in Figure 7, would require a much larger set of samples because of the switching cycles present. For a 20us switching cycle that must be resolved to 1us/sample, at least 4,000 samples would be needed to store 4ms of simulation results. A 10us switching period would require 40,000 samples. These are only a small fraction of the half-million time points typically seen in the original simulation results, but they exceed the practical limits of the function generators.

Figure 7 A Pulsewidth Modulated Waveform (mocked up by adding the sawtooth V_sample to the R-L-C output V_pls_out)

The solution to this problem is the topic of Part 2 of this series. Keep a watch for that blog.

### The honor is mine, my friend

I learn something new every time I have the good fortune to work with you, Mike. Thanks for sharing this on my behalf.

### beyond data reduction - Waveform sampling and DSP applications

Waveform sampling as described in this blog has a powerful application that extends beyond minimizing the amount of data stored. It opens the door to digital signal processing operations including DFT and FFT, linear filtering and averaging to filter out switching cycle details. I leave these thoughts as topics for future blogs. For now I'd like to mention the consequences that apply to the waveform sampling operation

First of alll you'll note that periodic strobe signals used to sample the waveforms result in uniform sampling. The period of the strobe signal tells you how many samples will be generated over the course of a transient simulation. You should be sure to retain exactly that number of time points in excel and don't forget that the first sample counts as zero times the strobe period. A simulation out to N times the  strobe period produces N+1 samples.

For signal processing operations the Nyquist rule requires that the strobe source period be set to sample at a rate equal to or greater than twice the maximum frequency of the signal. A factor of three or more is safer than the minimum sampling rate.To be strict about this the simulation should pass any signals you want to sample through a low-pass filter.

For AC analysis, Nyquist sampling translates into a requirement that the transient simulation run for at least twice as long as the time it takes for the signal(s) sampled to decay to zero. If you follow this rule you can safely fiter the sampled data whether you include the filtering in an AC or transient simulation.

If you follow these rules you can revisit the stored data to process the waveform data or apply it correctly to future simulation studies. For SystemVision Cloud users this may be a more important benefit than data reduction.