force-srate question

Hi, I’m completely new to Nyquist and fairly inexperienced with Audacity so please pardon if this question is too basic. I’m trying to demonstrate aliasing to my students and I thought Audacity would be an ideal platform for the students to play around with this and many other aspects of signals and systems. I can do that somewhat using the bandlimited resampling under the Tracks menu if I switch off High Quality Sinc interpolation. I’d like to do a naive resampling with linear interpolation using force-srate.

So here is an example of what I get, although this particular example would not show aliasing:

I generate a 400 Hz sine wave for 30 sec sampled at 44100 Hz.

I select all of the signal.

I pull up a Nyquist prompt and enter (force-srate 22050 s).

Nyquist then spits out a signal that is only 15 sec duration.

I had expected the duration would remain the same and the signal would only have half the number of points.
TIA for any suggestions that set me straight on this.

ETA: OK I found the answer here. Nyquist and Audacity do not share the sampling rate parameter.

Thanks much to steve.

Live and Learn. Should be a very good demo for the students to play around with.

Nyquist and Audacity are two different things. The Nyquist interpreter runs inside Audacity as a sub-program in its own world. This means that the Nyquist “force-srate” function changes the sample rate only in Nyquist, but not in Audacity.

What happens is that Nyuist returns a sound with a samplerate of 22050Hz, but the Audacity track samplerate is still 44100Hz, so the sound returned by Nyquist appears in Audacity with the half length and double frequency.

To get the desired effect (demonstating aliasing) you need to change the Audacity track samplerate manually to 22050Hz after Nyquist has returned the sound.

Example with Audacity 1.3.12-beta:

  • I generate a 30 seconds sine wave with 16000Hz (400Hz is too low for aliasing) in a 44100Hz Audacity track via “Generate > Tone”.

  • I select all of the signal.

  • I open the Audacity “Effect > Nyquist Prompt”, write (force-srate 22050 s), and click “OK”.

Nyquist returns a sound with 22050Hz sample frequency into a 44100Hz Audacity track, so the duration of the sound in Audacity is now 15 seconds with double frequency.

  • I change the samplerate of the Audacity track by “Track menu > Set Rate > 22050Hz”.

Now Audacity displays an plays back the correct 8000Hz mirror frequency, produced by the aliasing.

If I do the same with “Effect > Nyquist Prompt” and (resample s 22050Hz), then Nyquist returns a piece of silence with 22050Hz because 16000Hz cannot be represented with a samplerate of only 22050Hz, so the Nyquist “resample” function has “silenced away” the sine wave, what is absolutely correct.

Note: Nyquist cannot change the Audacity track samplerate, the Audacity track samplerate must be changed manually after Nyquist has returned the sound.

Two “full automatic” workarounds would look like this:

(resample (force-srate 22050 s) *sound-srate*)  ; aliasing
(resample (resample s 22050) *sound-srate*)     ; no aliasing

Where sound-srate is a built-in Nyquist variable representing the samplerate of the Audacity track, so the 22050Hz sound gets automatically resampled back into the samplerate of the Audacity track, where it is displayed in the correct length and frequency.

  • edgar

Perfect Edgar, thanks so much. I’m getting textbook aliases in the power spectrum.