Sunday, March 13, 2016

About beats

The sin function has the amazing mathematical property that it retains its shape when you add two sine waves of the same frequency, regardless of the amplitudes and phases. In formulas:

a1 sin(w t + p1) + a2 sin(w t + p2) = a sin(wt + p)

whereby w=2 PI f. f is called frequency and it is defined as the inverse of the period. w, which is just proportional to frequency also has a name, we call it "pulsation".

It can be shown the sin function is the only periodic function having this property, which thus defines it. The way to find out a and p relates to the geometrical definition of the sin function. Imagine a unit vector (unit means of magnitude 1) sweeping over the unit circle with constant angular speed w, that means it sweeps same angles in same time intervals, however short or long a chosen time interval is. We could also say the linear speed is constant, because linear speed and angular speed are related by a constant factor, since given an angle a its arc is just the angle times the radius. This comes out from the proportion: a: 2 pi=arc:2 pi r, given that we measure the angle a in a scale that goes from 0 to 2 pi for the round angle (full circle). So arc = a r, but if r is one then arc = a on the unit circle. The constant factor is simply 1 in our case.

The y coordinate of the sweeping unit vector at a certain angle a is by definition the value of the sin function at that angle. If at time t=0 the vector lays on the x-axis, that is its ordinate is 0, we have:

y = sin(a)

but the pulsation w=a / t=constant, so a=w t, so:

y  = sin(wt)

Summing up two sin functions with the same frequency equates to summming up two vectors with the same angular speed. By making use of the Pythagoras theorem, we can work out a and p (amplitude and phase of the resulting sine wave). This is left as an exercize for the more  math-enthusiast readers.

The importance of the sin function is capital in science because it is used to represent periodic phenomena like oscillations. Sound waves are just made up of local oscillations of air particles and the pressure they exert on your eardrum also varies with the same waveform.

How does a sin function representing sound pressure levels sound like? If you just send it as an electric signal to a loudspeaker, you can hear it. Building the electronic for this may be time-consuming and off-topic, so let's just use the computer hardware with the Audacity software to get the same result.

In Audacity go to the Generate menu and select Tone. Make sure the waveform is Sine, set the frequency to 200 Hz (200 oscillations per seconds), amplitude to 0.8 and duration to 15s. Audacity scales sound amplitudes linearly between -1 and +1, with 0 representing silence. From the View menu you can zoom the waveform out and in, or just use kyeboard shortcuts: ctrl-1 to zoom in, ctrl-3 to zoom out, ctrl-2 to return to default zoom level. You can also make a selection by clicking and dragging the mouse on the waveform. Hit ctrl-e to zoom that selection so that it takes all the horizontal space available in the Audacity waveform track view. You can see the generated tone has a phase of 0, that is it starts from 0 (silence) at t=0 and goes up in a positive sin halfwave. Press the play button to hear it. You will also hear a click at the end and the beginning of it, because of its abrupt rising and falling, which is rather artificial. We could select one or half a second at the beginning and use Effect/Fade In and similarly at the end using Effect/Fade Out, but we do not bother.

The sin function describes a pure tone. Musical instrument notes are never pure tones. They are made up of the sum of many different sin functions, with different frequencies. Record a note on your guitar or piano of whatever, look at the waveform details by zooming in: you will see an attack, a sustain and a decay phase. Using Analize/Plot Spectrum you can see how many frequencies other than the principal (or "fundamental") there are. Compare it to the spectrum of the sin tone.

Now to beats. What are they? How do they originate and what is their effect on our hearing? In order to find out, add another track using Track/Add new/Mono track. Then generate a tone with a slight higher frequency, let's say 200.1 Hz, just 0.1 Hz higher. Play them together while looking at the waves zoomed in enough for you to see single oscillations well.

Using the solo or mute track buttons, compare the two tones together mixed with a single one. In the former case you will hear a tone fading out from maximum loudness to zero, then fading in to maximum amplitude and at last fading out again. You will also notice, if you look at the sliding waveforms, that the sound is loudest when the two shifted waveforms are in phase, that is they happen to have the crest at the same time or about the same time, so they reinforce each other. On the contrary, when they are in opposition, that is one has a crest and the other a trough, they tend to cancel each other and you hear nothing or almost nothing.

To confirm these observations, lets now actually add (mix in jargon) the two sounds and look at the resulting waveform. For comparison we will do that in a new track. Since 0.8+0.8=1.6 which is greater than 1.0, distortion will result if we mix the tracks as they are (sin waves crests and troughs will be abruptly cut horizontally and the resulting sound will be too loud). So first reduce amplitude of both tracks by 10 dB using the +- slider: slide it to the left until you see "Gain: -10 dB". Do not change the LR balance slider, that is another thing.
Then select both tracks by shift-clicking on their left informative panel and choosing Tracks/Mix and Render to New Track. Click the Solo button on the resulting track and listen it, while watching at its waveform shrinking and rising.

It will be informative to hit Ctrl-2 to return to normal zoom level.

You will see one and a half beat! Now a bit of simple math, just arithmetic. If we have 1.5 beat in 15 seconds, that means that a single beat lasts 15/1.5 seconds/beat, that is 10 seconds/beat. In plain words, a single beat lasts 10 seconds. Select the last whole beat and you will see the selection length to be about 10 seconds indeed. Since frequency is the inverse of period, the beat frequency will be 1/10 seconds^-1=1/10 Hz=0.1 Hz, because we call Hertz what actually is 1/second. Now subtract the two original waveform frequencies: 200.1-200 Hz=0.1 Hz. Hey! That's exactly the beat frequency! So here is how the beat frequency is determined.

Now the real fun is going to begin. Armed with this simple formula to determine the beat frequency (just subtract tone frequencies), you are going to experiment the effect of higher and higher beat frequencies to your ears. What you will conclude is that when the beat frequency is higher enough, you are not able to hear single beats anymore, but they melt together and the result is more pleasant, like a single note, especially at higher differences.

You can approximately measure the resulting note frequency by zooming in and
select a single period and count samples in a period. Let Audacity count samples for you by clicking on the down arrow of the selection length entry and choosing the "hh:mm:ss + samples" format. If you multiply the number of samples in a period by the time interval between each sample, you will of course get the period length. Given a standard CD sampling frequency of 44100 Hz, that means that 44100 samples are taken in one second, so each sample spans a duration of 1/44100 seconds. Multiply 1/44100 by the number of samples in a period to get the period length in seconds. But the opposite of this is by definition the wave frequency, so if you divide 44100 by the number of samples in a period, you will directly get the wave frequency, at least for that period, if frequency varies (we say the wave is "modulated" in frequency).

E.g. let's combine two single tones at 82 at 87 Hz frequency. These are the fundamental frequencies of the two lowest notes on a guitar in standard tuning. 82 Hz is the 6th string (thickest string) played open, 87 Hz is the next highest note just one fret down, that is the note on the 6th string, first fret. You will hear the result is a "wobbling sound" because there are audible beats, namely 87-82=5 beats per second. So it does feel like two notes oscillating one into another alternatively, without a resolution.

In theory they will say it's a "minor second" interval (they give it this absurd name, it's just a one-semitone interval) and it is "dissonant", a "rather sharp dissonance". For this reason you will not have a lot of classical music using these two notes in a chord. In this case this is almost sure, because you can't play that with the guitar, since you cannot fret both notes at the same time. They are the two lowest notes and there is no other position to fret the second one at the same time of the first one. But two guitars can make it.

If you have a guitar with a mic inside (or you can put a cheap usb mic inside temporarily and use Effect/Amplify if the recorded volume is too low), you can sound these two notes one at a time, record them to separate tracks and sound them together with Audacity. You will experience a distorted resultant noise. Hurrah! Here is a poorman guitar distortion tecnique :-)

So with pure tones, you only hear the beats, while with tones with timbre, you have distortion.

Of course no distortion occurs if you try and play the two lowest notes on the guitar in sequence or slide them (play the 6th string open and slide from the nut on the neck just behind the first first). It sounds good, doesn't it?

Now we are going to play together something like the two most high (high in pitch) notes on a 12-fret classical guitar. It's the 11th and 12th fret on the 1st (thinnest) string. On my classical guitar the 12th fret is where the neck meets the body of the guitar. Their frequencies are about 622 and 659, which means a beat frequency of 659-622= 37 Hz. You will see that since the beat frequency is higher, each beat lasts less and so beats tend to melt together making a sort of cricket sound. If we would consider sounds even higher, spaced more than one fret, as those of a folk or electric guitar with more accessible frets, the beat frequency would be higher.

You may now be curios about what happens with real instrument notes, which are not pure tones and have overtones. So go and play the two most highest easy-accessible tones on a 12-fret classical guitar, record them separatedly and mix them in. You still have dissonance and a bit of distortion, but much less.

If you play together two tones at 82 and 92, you will have 10 beats per second. It sound like a pneumatic drill! Then try 82 and 98. It sounds like an engine. Then 82 and 104. It sounds like a helicopter :-) Then 82 and 110 sounds like vibrations nearby an electric cabinet.

Very different results you get with real tones having more frequencies other than the fundamental (called "overtones"). 92 is the 2nd fret on the 6th string, together with 82, the 6th string open (by recording the two notes separately and mixing) does not sound bad at all. One way to explain that would be this. The frequency ratio 92/82= 1.12 is not very far from 5/4=1.25. Indeed next notes (3rd fret and 4th fret) get nearer to 5/4. 4th fret is 104 and 104/82=1.27~1.25. What has 5/4 of so special? Just because it is a ratio between small integers like 5 and 4. Let's pretend to ease calculations that the frequencies are 80 a 100 Hz. Since 80* 5/4 = 100, they are in 5/4 ratio, because 5/4= 100 / 80 as well. Now take the highest frequency and multiply it by 2, 3, 4, etc:

100 * 2 = 200
100 * 3 = 300
100 * 4 = 400
100 * 5 = 500
100 * 6 = 600
100 * 7 = 700
100 * 8 = 800

do the same with the other:

80 * 2 = 160
80 * 3 = 240
80 * 4 = 320
80 * 5 = 400
80 * 6 = 480
80 * 7 = 560
80 * 8 = 640
80 * 9 = 720
80 * 10 = 800

you see they share some integer multiples of the base frequency like 400 which is both 80*4 and 100*4, but also 800 which is both 100*8 and 80*10. Especially the first shared multiples will have more energy and since they have the same frequency they melt together well. This is why we said only "small integers" produce this nice melting effect which gives consonance.

For this reason ratios like 2/1 (or 1/2 depending on how you write it) are even more consonant, e.g. 6th string open and 4th string at the 2nd fret. Try to pick or pluck these two notes together on your guitar and then individually. They go very well together.

To summarize frequency ratios of (about) 2:1, 3:2, 4:3, 5:3, 5:4, and 6:5 are consonant, in order from most to least consonant (remember, the lowest the numbers the better, so 5:3 comes before 5:4 because 3 comes before 4). These frequency ratios are very used in guitar chords. They are confusely called intervals, but they are really ratios, not differences! We better call them ratios, forget the interval name. 1:1 is the unison, same sound, banal consonance. Why we do not have 1/3 in the list? Well, that is equivalent to 3:1 and is greater than 2. It is also a consonant interval, but between two notes in differet octaves, since it is greater than 2. For example pick the 5th string at the 3rd fret (131Hz) together with the 1st string at the same 3rd fret (392 Hz). Since 392~131*3 we have a 3:1 ratio that is consonant. This is just twice the 3:2 interval, that is 3:1=3:2 * 2. Similarly 4:1 is twice 2:1, 5:2 is twice 5:4, etc.

References for a more detailed study:

No comments: