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:
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.
Modulator frequency: The frequency of the sine wave being generated. This is capped internally to a maximum of one-fifth the carrier frequency.
Duration: The length of the clip.
Mod depth: The ratio of the output square wave’s peak voltage to the sine wave’s peak voltage.
Dead time: The amount of time when both switching transistors or thyristors are off (may not be visible).
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.
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).
Width offset: Specifies the DC offset of the output waveform. Normally this is 0.
Amplitude: The amplitude of the generated square wave (between 0 and 1).
Notes:
Some of the code in this plugin was created with the help of AI (Claude Opus 4.7).
3- and 5-level generation is based on phase-shifted PWM using cascaded H-bridges.
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.
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)
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)