VFD PWM waveform generator

This plugin simulates the output of variable frequency drives (VFDs) by generating a PWM with a triangle wave carrier and a sine wave output. It allows you to visualise and hear PWM waveforms. This is a heavily modified version of pwm.ny.

Parameters:

  1. Carrier frequency: Also known as the “switching frequency”, this is the frequency of the triangle wave being used to generate the PWM and corresponds to how rapidly the output transistors or thyristors switch on and off.
  2. Modulator frequency: The frequency of the sine wave being generated. This is capped internally to a maximum of one-fifth the carrier frequency.
  3. Duration: The length of the clip.
  4. Mod depth: The ratio of the output square wave’s peak voltage to the sine wave’s peak voltage.
  5. Dead time: The amount of time when both switching transistors or thyristors are off (may not be visible).
  6. Third harmonic injection: Adds a sine wave with 3 times the frequency and 1/6 the amplitude of the modulator and scales the output by 2/√3. This allows about 15% more voltage to be obtained from the same peak amplitude.
  7. Output levels: Specify whether the inverter being simulated is 2-level (+V, −V), 3-level (+V, 0, −V), or 5-level (+V, +V/2, 0, −V/2, −V).
  8. Width offset: Specifies the DC offset of the output waveform. Normally this is 0.
  9. Amplitude: The amplitude of the generated square wave (between 0 and 1).

Notes:

  1. Some of the code in this plugin was created with the help of AI (Claude Opus 4.7).
  2. 3- and 5-level generation is based on phase-shifted PWM using cascaded H-bridges.
  3. Generating longer samples may take a while, as visualising high-frequency PWM waveforms accurately often requires very high sample rates (several MHz). You may want to limit yourself to just 2 seconds maximum with high carrier frequencies.

Oh, and that “5.2 KB” figure is wrong. It’s actually 5,369 bytes, which should read “5.4 KB”.
pwm_blimit.ny (5.2 KB)

I hope you carefully checked what AI told you. Last time I tested AI with Nyquist code it made lots of errors. There isn’t much training data for Nyquist, so it commonly mixed in syntax from Common Lisp along with syntax that does not exist at all.

A couple of points from skim reading the code:

;action and info headers are legacy and not supported in version 4 plug-ins. They are silently ignored, so those lines are harmless.

;; --- Enforce: carrier must be at least 5x the modulator frequency ---
(setq carrier (max carrier (* 5.0 f)))

Note that carrier must also be less than half the sample rate.

I hope you carefully checked what AI told you. Last time I tested AI with Nyquist code it made lots of errors. There isn’t much training data for Nyquist, so it commonly mixed in syntax from Common Lisp along with syntax that does not exist at all.

I did, and I had to re-prompt it multiple times. One of the errors I got was because of this.

;action and info headers are legacy and not supported in version 4 plug-ins. They are silently ignored, so those lines are harmless.

Note that carrier must also be less than half the sample rate.

Noted, I put in a cond statement afterwards to get these sanity checks in
pwm_blimit.ny (5.7 KB)

It’s nice to see that Nyquist is still getting some attention :slight_smile:

There’s a couple of additional headers that you might like to add;

;author "Your Name"
Displays your name as the “Vendor” in the plug-in “Presets & Setting > About”

;release <number>
Displays a version number in “Preset & Settings > About”. If the version string has spaces it should be in double-quotes.

;copyright "GNU General Public License v2.0"
Displays the license as “Description” in “Preset & Settings > About”.

A couple of suggestions:

Perhaps use kHz for the carrier frequency to make the slider easier to use, or, if you intend text input only use a float-text or int-text control.

Consider using a “time widget” for setting the duration.

pwm_blimit.ny (5.8 KB)

That works, but did you intend to increase the default length 16m 40s?

Whoops, forgot to scale the default values when I changed from a text entry to a time widget. Also, oversampling increased from 8x to 16x.
pwm_blimit.ny (6.4 KB)