Hi all . I am a long time fan of audacity (presently 2.1.3). I want to use it to demonstrate features in musical sound to my pupils. I find there are many basics that are simply glossed over (mathematically speaking)

I wanted to start with simple pure sine waves and show additive synthesis but the generate/tone feature gives a tone with way too many sub harmonics eg starting with 500 Hz I get 250, 125 giving a very impure result for demonstration purposes. (strange cos harmonics are normally higher multiples of the fundamental? - cant get my head round that? Is it something to do with the way Aud approximates a sine wave - from a wave table maybe?

Can anyone suggest another way to get a pure note from Aud?

I can only think of making my own WAV and using that (if I can make one pure enough)

## generate/tone

**Forum rules**

**If you require help using Audacity, please post on the forum board relevant to your operating system:**

Windows

Mac OS X

GNU/Linux and Unix-like

### Re: generate/tone

That's a pretty old version. The current version is 2.3.2 and is available via the Audacity website: https://www.audacityteam.org/download/

I suspect this is due to some kind of "user error", because "Generate > Tone", when "Sine" is selected, produces an extremely pure sine wave.

(If "Sawtooth" or "Square" are generated, there will be sub harmonics due to aliasing).

Assuming that you have not accidentally generated the wrong shape waveform, how are you measuring the waveform that indicates sub-harmonics?

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

### Re: generate/tone

thanx steve I have duly updated my audacity to 2.3.1. I tend to go on the priniciple, if it aint broke dont fix it, so no doubt my old version was 10 years old - tribute to Audacity (but then I still keep a working machine with XP sr3)

Indeed I think I am misunderstanding the screen traces. I am trying to get a handle on Analysis/plot spectrum - more work needed

One thing that has been bothering me about additive synthesis is

sin(A)+ sin(B) = 2 (sin((A+B)/2) x cos((A−B)/2))

This is a well known trig formula

but it doesnt shown the beat frequency you get from mod| B-A|

Im not sure how to obtain the harmonics from the product of two sines (some kind of fourier expansion technique?)

Hope you can see what I am trying to explore here

As is well known to musicians, when you add two tones you end up with a timbre and a beat

I want to be able to explain how eg you add a tonic say middle A 440 plus a fifth above 660. You will get a diad chord and a sub tonic at 220hz. I presume in this case that the subtonic will also interact with the tonic plus the fifth above etc

I have never found this aspect dealt with anywhere

I thought Aud would be a good experiment vehicle if I can master the interpretation and limitations of the FFT

Indeed I think I am misunderstanding the screen traces. I am trying to get a handle on Analysis/plot spectrum - more work needed

One thing that has been bothering me about additive synthesis is

sin(A)+ sin(B) = 2 (sin((A+B)/2) x cos((A−B)/2))

This is a well known trig formula

but it doesnt shown the beat frequency you get from mod| B-A|

Im not sure how to obtain the harmonics from the product of two sines (some kind of fourier expansion technique?)

Hope you can see what I am trying to explore here

As is well known to musicians, when you add two tones you end up with a timbre and a beat

I want to be able to explain how eg you add a tonic say middle A 440 plus a fifth above 660. You will get a diad chord and a sub tonic at 220hz. I presume in this case that the subtonic will also interact with the tonic plus the fifth above etc

I have never found this aspect dealt with anywhere

I thought Aud would be a good experiment vehicle if I can master the interpretation and limitations of the FFT

### Re: generate/tone

No, it won't do, because the FFT resolves the waveform into A and B.

You need to approach it the other way round:

Generate a "Square, no alias" waveform at 100 Hz. It looks like this when you zoom in:

If I zoom out a bit and select 0.1 seconds, then as expected, you can see 10 positive going peaks within the 0.1 second selection:

From this we can deduce that the fundamental frequency is 100 Hz (10 cycles in 0.1 seconds = 100 cycles per second).

We know that a square wave can be created from the sum of harmonics (and in fact, that's how the "Square, no alias" is generated), but can we "see" these harmonics? Yes we can, by looking at the Track Spectrogram view (https://manual.audacityteam.org/man/spe ... _view.html). I've stretched the track vertically so that we can see it better:

and also in Plot Spectrum:

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

### Re: generate/tone

Audacity has a scripting language built in called "Nyquist". It is very good for this sort of thing.

Here's an example script that sums the first 8 harmonics of a "square" wave:

Code: Select all

```
;version 4
(setf harmonics 8) ;number of harmonics
(setf hz 100) ;fundamental frequency
(setf wave (s-rest 1))
(setf amp 0.5)
(dotimes (hnum harmonics wave)
(setf f (* hz (+ 1 (* hnum 2))))
(setf amplitude (* amp (/ 1.0 (+ 1 (* hnum 2)))))
(setf wave (sum wave (mult (hzosc f) amplitude))))
```

Some brief explanation:

A semicolon indicates the start of a comment. Comments are ignored by Nyquist.

The first line (;version 4) is a special comment that tells Audacity that we are using version 4 syntax. It is not strictly necessary in this case, but it's good practice to include the syntax version number.

"Nyquist" is based on the LISP language. Functions are always written as:

Code: Select all

`(function-name arguments)`

2 + 3

In LISP / Nyquist, we write:

Code: Select all

`(+ 2 3)`

Example:

Code: Select all

```
(setf A 4) ;sets the value of 'A' to 4
(print A) ;prints 4
```

Here's an overly commented version of the script:

Code: Select all

```
;version 4
(setf harmonics 8) ;number of harmonics
(setf hz 100) ;fundamental frequency
;; Begin with "duration" of silence
(setf wave (s-rest 1))
;; and an initial amplitude of 0.5
(setf amp 0.5)
;; Add the sine tones
;; 'hnum' is the harmonic counter, and we increment it,
;; starting from zero, on each loop, up to the value of 'harmonics',
;; and return 'wave'.
(dotimes (hnum harmonics wave)
; Calculate required frequency:
(setf f (* hz (+ 1 (* hnum 2))))
(print f) ;prints the frequency to the debug output
; Calculate the required amplitude:
(setf amplitude (* amp (/ 1.0 (+ 1 (* hnum 2)))))
;; Generate the new sine wave and add it to 'wave'
(setf wave (sum wave (mult (hzosc f) amplitude))))
```

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)