Nyquist prompts for AM and FM

It would be great if AM and FM were available in the drop downs, as in Adobe Audition. Seeing as they are not, I am looking for exactly what to type in the Nyquist prompt box. I don’t want to spend hours learning Nyquist just to derive two functions, eg. AM and FM of sinewaves. That’s all I, and probably alot of other users, will ever need.

Can someone please walk me through how to implement, as a Nyquist prompt, the following two functions?

Example 1: Amplitude modulate a 100Hz sinewave (track A) with a 10Hz sinewave (track B).

Example 2: Frequency modulate a 100Hz sinewave (track A) at 10Hz (track B) with a 10Hz deviation.

I have already spent quite a bit of time on the net, but was unable to find a solution I could understand.

Many thanks,

Paul Nielsen

Amplitude modulation is a simple “multiplication” function, like a “tremolo” effect.

There is the “signal” that you want to modulate, and the “modulation wave”.
The “modulation wave” usually has a much lower frequency than the “signal” wave, though interesting effects can be achieved when the two frequencies are quite close together.
The “modulation wave” should normally have a range between 0 and +1 (linear), though more subtle effects can be achieved by using a smaller range below +1.

There is immediately a problem here in that Nyquist can only access one track at a time.

The simplest way to act on two mono tracks, is to manually join them into a single stereo track before you apply the Nyquist effect. See here for how to do that: http://manual.audacityteam.org/man/Splitting_and_Joining_Stereo_Tracks

Audio (mono or stereo) is passed to Nyquist in a global variable “S”. In the case of a mono track, “S” is a “sound”. In the case of a stereo track “S” is an “array” of two sounds - the left channel (upper channel in Audacity) is the first element in the array and the right channel is the second element.

Array elements are numbered starting from zero.
To access an array element we use the function AREF Appendix 3: XLISP: An Object-oriented Lisp
So to access the left channel of a selected stereo track we can use:

(aref s 0)

and for the right channel:

(aref s 1)

The amplitude of normal audio tracks usually in the range +/- 1 (the vertical track scale), but we want the “modulation wave” to be in the range 0 to +1.
We can change the range quite easily by adding 1 to each sample value, then dividing by 2 (x 0.5).
To do this to the right channel of a stereo track:

(mult 0.5 (sum 1 (aref s 1)))

We then want to modulate the “signal wave” (the left channel) by this modified right channel. As said at the top, amplitude modulation is simply multiplication, so we can write:

(mult (aref s 0)
  (mult 0.5 (sum 1 (aref s 1))))

or more simply:

(mult (aref s 0) 0.5 (sum 1 (aref s 1)))



How did I do? Could you follow that?

Note that if you only want to modulate simple tones, then rather than messing around with combining tracks into stereo, you can simply generate the tone. For example, to modulate any Audacity track with a 10 Hz sine wave:

(mult s 0.5 (sum 1 (hzosc 10)))

Do you see how this works?
Note that the MULT (multiply) function can be used on mono or stereo sounds as well as with numbers.

Frequency modulation is rather more tricky when using recorded and there are different ways to accomplish the task depending on how long the duration of the sound is. It is much more simple with generated sounds because we can simply use the function FMOSC Nyquist Functions

(fmosc pitch modulation [table phase]) > [LISP]
Returns a sound which is table oscillated at pitch plus modulation for the duration of the sound modulation. osc-table defaults to table, and phase is the starting phase (default 0.0 degrees) within osc-table. The modulation is expressed in hz, e.g. a sinusoid modulation signal with an amplitude of 1.0 (2.0 peak to peak), will cause a +/- 1.0 hz frequency deviation in sound. Negative frequencies are correctly handled. The sample rate is sound-srate.

The definition in the manual is probably quite hard to follow, so here is an example:
Frequency to modulate = 440 Hz
Mudulated at a rate of 5.5 Hz
With a deviation of 12 Hz (+/- 6)

(fmosc (hz-to-step 440)(mult 12 (hzosc 5.5)))

The examples you’ve listed do not Need any Input from the tracks itself.
The Syntax is quite simple (extract from my nyquist-reference plug-in):

LISP-syntax for this Function (9/358):
(AMOSC PITCH MODULATION &OPTIONAL (SOUND *TABLE*) (PHASE 0))
Category: Oscillators, as found in :  Nyquist.Lsp

Description:
Returns a sound which is table oscillated at pitch. The output is multiplied by modulation for the duration of the sound modulation. 
osc-table defaults to *table*, and phase is the starting phase (default 0.0 degrees) within osc-table. The sample rate is *sound-srate*.

pitch is the frequency of the carrier in half steps (midi notes). We therefore must translate the 100 hz Signal into such a step. The Modulation can be done with ‘hzosc’ or ‘lfo’ which produces a sine wave at the specified frequency with the length of the current selected track.

(amosc (hz-to-step 100) (hzosc 10))

The difference between hzosc and lfo: the first has a samplerate of 44100 (or whatever is Chosen for the Project) and lfo has 2205 - which is enough for such low frequencies.
Fmosc works just the same but you have to multiply the Modulation Sound by 10 to produce the Variation for +/- 10 Hz (or with 5, if the range in total is 10 Hz).

(fmosc (hz-to-step 100) (mult 10 (lfo 10)))

You can also use the current selection as the Modulation Input:

(fmosc (hz-to-step 100) (mult 10 s))

I hope this helps.

The responses so far have been excellent and straight to the point.

Having the procedure for these type of basic “non-musical” wave functions clearly given in the manual might be worth looking into. Apart from sound synthesis, they make Audacity useful as an AF function generator for electronics enthusiasts. Other operations might include DC offset, ramps, sweeps, etc. Just a dozen all up really.

Paul Nielsen

I was a bit surprised that I couldn’t find plug-ins for generating AM/FM tones, so I’ve made a pair of plug-ins and posted them here: https://forum.audacityteam.org/t/am-and-fm-tone-generators/29422/1