# generating 500hz tone at 1000 hz sample rate doesn't work

I set my sample rate to 1000hz and then generate a tone at 500hz the audio is blank and there is nothing there.
499hz creates waves, but anything above that appears to be blank. What gives?

Please do not double post. A given sample rate can only carry frequencies up to half that rate. Please see: http://www.sweetwater.com/insync/nyquist-frequency/.

Gale

I’d also highly recommend these two videos about digital audio:
http://xiph.org/video/

Here’s a curiosity for you:

• Set the Project Rate to 1000 Hz.
• Select part of the track.
• Open the “Nyquist Prompt” effect (Effect menu).
• Enter the following code into the Nyquist Prompt text box and click the OK button:

``````(setq phase 90)
(osc (hz-to-step 500) 1 *sine-table* phase)
``````

Zoom in really close to see the waveform

“Phase” sets the “starting point” of the waveform; whether it is at the top, middle, bottom of the sine curve, or somewhere else.

Now repeat that, but try different values for “phase”, for example:

``````(setq phase 45)
(osc (hz-to-step 500) 1 *sine-table* phase)
``````

What happen if you set “phase” to zero?

``````(setq phase 0)
(osc (hz-to-step 500) 1 *sine-table* phase)
``````

If you want it to not care about the relationships between sampling frequency and audio tone, pick a Nyquist value of 2.6 minimum. Nyquist of 2.0 depends on too many tricks and sloppy electronics to work reliably under all circumstances. As above, it can be faked out.

Koz

499hz creates waves, but anything above that appears to be blank. What gives?

At a frequency of half the sample rate you get two samples per cycle… One sample-point for the positive-half of the “waveform” and one sample-point for the bottom half of the “waveform”. (If that doesn’t make sense, [u]this tutorial[/u] explains how audio is digitized/sampled.)

Mathematically, the sine of zero-degrees is zero, and the sine of 180 degrees is also zero. If you try to generate a sine wave at one-half of the sample rate, ALL of your samples end-up at zero-degrees and 180 degrees* (where the wave passes-through the zero-crossing) and you’ll get a series of zero-value samples = DIGITAL SILENCE!

However, the cosine of zero degrees and 180 degrees is 1. If you generate a cosine wave at half the sample rate it, will work!

\

• To be more precise, all of the samples lie at multiples of 180 degrees (and all multiples of 180 degrees have a sine equal to zero). So, a sine wave has a value of zero (a zero-crossing) every 180 degrees.

@Doug, I changed your link to point to the equivalent article in the current Manual, rather than the obsolete 1.2 Manual. Thanks!

Gale

The Square Wave choice in Generate > Tone works at half the sample rate in terms of being audible, though the waveform looks untypical of a square wave.

Gale

and “Square (no alias)” produces silence.
To see why, look at the starting point of the waveform when generating a tone well below the Nyquist frequency. The starting point will be the first dot, then there will be dots for each consecutive 1/2 cycle.

It’s the same as a cosine wave–the zero crossings are mid-point between samples thus you do not have the zeros from the sine wave.
By the way, shouldn’t we have a little bit more than the current wave-forms?
For example:

• Saw-tooth, no alias
• Triangle (+ no alias)
• Buzz (summation of cosines up to Nyquist, gives single impulses at <=1 Hz)
optionally:
• square waves with other duty factors, not only 50 %.
• sine bursts

OK, I made a note of that.

Gale

There is a plug-in here that offers a wider range of waveforms: New plug-in: Tone Generator
and one here with a range of “no alias” waveforms: High Quality (no alias) Tone generator

Perhaps these should be combined into one plug-in and uploaded to the wiki?

+1 if you can. I find it too hard to locate plug-ins in New Plug-Ins - Audacity Forum and often a search will produce several similar plug-ins that are the same as each other except for one or two different controls.

Gale

I still think that the changes should go directly into audacity’s shipped effect.
It makes no sense to have a alias-free square wave but no alternative to saw-tooth.

Perhaps we should ship the Nyquist tone generator instead of the current built in Tone generator.
For the non-alias versions, the Nyquist effect is much faster than the built-in effect, particularly for low frequency waveforms, and we could have a Preview button if we wished to.

Sure, why not.
Should we have a “Allow Aliasing” control instead of doubling the wave-forms?

That makes sense.

Do you think that it is worth having a Preview button on a simple waveform generator? I’m thinking perhaps not as it is not an effect that users are going to be able to “tweak”, though it may be instructive if users can quickly hear the tone difference between allowing or not allowing aliasing.

“Instructive” is the keyword here. It might be helpful for total novices to experiment without reenter the tone generator again and again.
Also, amplitude and frequency are tweaked too, thus it is nice to set them on the fly.

Last but not least, the plug-in can display warnings as well, if the frequency is for instance >= Nyquist. The user has therefore a second chance to enter proper values when he’s tried the preview first.

I can think of 2 reasons why not:

1. For waveforms where aliasing is allowed, the built-in effect is quicker than the Nyquist effect.
2. The built-in effect has a time control widget for entering the duration (hh:mm:ss)

but also several reasons why the Nyquist version would be preferable:

1. MUCH faster generating low frequency alias free tones.
2. Can have a preview button.
3. Can easily be extended for additional waveforms.
4. Very easily maintained.