generate/tone

For Teachers and Educators.
Using Audacity in the Classroom.
Forum rules
ImageIf 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
Post Reply
robint
Posts: 2
Joined: Tue Jul 09, 2019 5:56 am
Operating System: Windows 8 or 8.1

generate/tone

Post by robint » Tue Jul 09, 2019 6:20 am

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)

steve
Site Admin
Posts: 81416
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: generate/tone

Post by steve » Tue Jul 09, 2019 8:58 am

robint wrote:
Tue Jul 09, 2019 6:20 am
presently 2.1.3
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/

robint wrote:
Tue Jul 09, 2019 6:20 am
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.
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)

robint
Posts: 2
Joined: Tue Jul 09, 2019 5:56 am
Operating System: Windows 8 or 8.1

Re: generate/tone

Post by robint » Tue Jul 09, 2019 4:01 pm

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

steve
Site Admin
Posts: 81416
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: generate/tone

Post by steve » Tue Jul 09, 2019 4:51 pm

robint wrote:
Tue Jul 09, 2019 4:01 pm
but it doesnt shown the beat frequency you get from mod| B-A|
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:

firsttrack000.png
firsttrack000.png (8.31 KiB) Viewed 2268 times

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:

firsttrack001.png
firsttrack001.png (8.61 KiB) Viewed 2268 times
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:
firsttrack002.png
firsttrack002.png (40.54 KiB) Viewed 2268 times
and also in Plot Spectrum:

fullwindow-Frequency Analysis-000.png
fullwindow-Frequency Analysis-000.png (58.3 KiB) Viewed 2268 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81416
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: generate/tone

Post by steve » Tue Jul 09, 2019 5:46 pm

robint wrote:
Tue Jul 09, 2019 6:20 am
I wanted to start with simple pure sine waves and show additive synthesis
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))))

You can run this in the Nyquist Prompt effect, by copying and pasting.

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)
For example, where we would normally write:
2 + 3
In LISP / Nyquist, we write:

Code: Select all

(+ 2 3)
"setf" is an assignment function. It sets the value of the first argument, to the value of the second argument.
Example:

Code: Select all

(setf A 4)  ;sets the value of 'A' to 4
(print A)   ;prints 4
When a Nyquist script runs in Audacity, the final result is returned to Audacity. In this case, the returned value is a sound which I have called 'wave'.

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)

Post Reply