## Listening to superimposed waves

Let me share a little experiment I did last night. Listen to the following audio first. This plays a sine wave of 500 Hz for 2 seconds followed by another sine wave of 500.1 Hz for 2 more seconds. You can hear a tick after each second. The 500.1 Hz sine wave starts at the second tick.

Could you notice any difference in the pitch of the two tones? The difference in the frequencies is so small that you wouldn't be able to notice it by hearing.

Now, let us see what happens when we superimpose both the waves and listen to it.

You would notice that the loudness decreases rapidly at about 5 seconds and then returns to full volume by 10 seconds, decreases rapidly again at 10 seconds and returns to full volume by 15 seconds and so on. In other words, the loudness decreases every 10 seconds.

Let us see why this happens from the graph of the waves. The first wave can be represented with the function f(t) = 0.4 sin (2π · 500 · t) and the second one with g(t) = 0.4 sin (2π · 500.1 · t)

At t = 0 seconds, both the waves look very similar. The crests and troughs of both the waves appear almost simultaneously. On superposition, the amplitude almost doubles. The graph of the superimposed waves is shown below. Note that the amplitude of each wave in the figure above is 0.4 while that of superimposed waves is almost 0.8 as can be seen below. In fact, it is exactly 0.8 at t = 0 seconds and then gradually decreases in the region 0 < t < 5.

The time period of the second wave is slightly shorter than the first one as the frequency of the second wave is slightly greater than the first one. So, the two waves are not identical. In fact, the second wave looks like a very slightly compressed form of the first wave. At about t = 5 seconds, the difference is obvious.

The crests and troughs of both the waves do not appear simultaneously at around t = 5 seconds. In fact, the crest of one wave and the trough of the other wave appear simultaneously. This cancels out each other on superposition and thus the resultant wave has almost no amplitude at this time.

The amplitude is exactly 0 at t = 5 seconds and it increases gradually till t = 10 seconds. At t = 10 seconds, the amplitude becomes 0.8 again and then starts decreasing till t = 15 seconds when it becomes 0 again. This cycle continues. This can be seen in the graph of the superimposed waves given below.

Let us understand this mathematically. Let us represent both the sine waves with the functions: y1 = A sin 2πft and y2 = A sin 2π(f + Δf)t, where A is the amplitude of the waves, and f and f + Δf are the frequency of the two waves.

So, the superimposed waves can be represented as

y1 + y2

= A sin 2πft + A sin 2π(f + Δf)t

= (2A cos 2π · Δf2 · t) sin 2π(f + Δf2)t

To understand this function intuitively, imagine it as a sine wave with a frequency of f + Δf2 and an amplitude of 2A cos 2π · Δf2 · t. In our case, f + Δf2 = 500.5 Hz. So, the superimposed waves look like a sine wave with a frequency of 500.5 Hz but with its amplitude varying with time at a frequency of Δf2. In other words, the amplitude oscillates between 0 and 2A every 1Δf seconds. Since Δf = 0.1 Hz and A = 0.4 in our case, we see that the amplitude of the 500.5 Hz sine wave oscillates between 0 and 0.8 every 10 seconds.

## Telling eggs apart

Last evening after I took out boiled eggs from my electric kettle, I tested a solution to a problem I once got from Anoop, an ex-colleague and a good friend.

How can we tell raw eggs and hard-boiled eggs apart?

One solution I knew from childhood experiments involves spinning the given egg, then momentarily stopping it with hand while it is spinning and then releasing it immediately. If the egg starts spinning again, it is a raw egg. If it doesn't, it is a hard-boiled one. This can be explained with Newton's first law of motion. One might even see it as a demonstration of Newton's third law of motion.

Anoop, a friend of mine, told me about another solution which I believe is simpler and uses the same principle as the one behind the solution I mentioned above. Can you guess this simpler solution?

Do you know other ways of finding out whether an egg is boiled or not without breaking it?

## Fun with tones and colours

I spent the last evening experimenting with sound and colours.

You will hear two pairs of tones separated by 2 seconds of silence. Each tone is 2 seconds long. The first tone has a frequency of 100 Hz. I won't tell you the frequency of the second tone right now. But you should notice that it is a little greater than the frequency of the first tone. You'll need good earphones to listen to this. Most laptop speakers can not play these low frequency tones well.

The third tone after the silence has a frequency of 400 Hz and you'll have to wait a little to know the frequency of the fourth tone.

Now, try to answer this question. Is the difference in frequencies in the first pair of tones equal to that of the second pair of tones? If you feel they don't sound equal, which difference sounds greater?

I hope you find the first change in frequency greater than the second one because that's how a normal human brain is supposed to perceive these differences in frequencies. If you do, you might be surprised to know the frequencies of the second and the fourth tone. The frequency of the second tone is 110 Hz and that of the fourth tone is 410 Hz. Yes, there is a difference of 10 Hz in both cases. Why then does the first difference sound greater than the second one? In fact, the first difference would sound roughly four times greater than the second difference. Why?

We sense pitch in a logarithmic fashion. Let me explain what this means. Let us consider a strange company which pays you one gold coin for every 2 days you work. Your income is directly proportional to the number of days you work. The number of gold coins is always half the number of days you work. You earn the gold coins in a linear fashion. The graph looks like this:

Now consider another company which pays one gold coin if you work for 4 days, two gold coins if you work for 16 days, 3 gold coins if you work for 64 days and so on. In other words, you earn n gold coins if you work for 22n days where n is a positive integer. The graph looks like this:
Note that the graph is no longer a straight line. That's why, in this case, the income is not said to grow linearly with the number of days of work. But note that the number of gold coins earned is half that of the exponent to which 2 is raised to equal the number of days. So, if we plot a graph of the gold coins earned versus these exponents, we should get a graph similar to the one we got for the first case. Have a look:
Note that the x axis is log2(number of days of work). log2(n) is the exponent to which 2 has been raised to equal n. So, we see that in this case, the number of gold coins earned is directly proportional to the logarithm of the number of days of work. Hence, the income here is said to be in a logarithmic fashion.

Similarly, the perception of pitch is directly proportional to the logarithm of the frequency of the sound.

There is another interesting thing to note in the second example. You earn one gold coin for 4 days of work. After 4 days, to earn an extra gold coin, 12 extra days of work is needed. The number of extra days required to earn an extra gold coin is 3 times the number of days of work done so far. This pattern holds throughout the graph. For example, after earning three gold coins with 64 days of work, 192 extra days of work is required to earn the fourth gold coin. This pattern holds true if you want to analyze how much extra effort is required to increase your income by 2 gold coins or any number of gold coins you want to consider. Try it.

So, at any point, to earn a certain number of gold coins, the number of extra days of work required is directly proportional to the number of days spent in work so far.

Our perception of pitch of sound is similar to the number of gold coins earned in the second case. The change in frequency (frequency of the second tone - frequency of the first tone) required to cause a certain perceived change in pitch is directly proportional to the frequency of the sound one is hearing. So, At 400 Hz, we need a change of 40 Hz to create the same effect as a change of 10 Hz at 100 Hz. The following audio demonstrates this. The fourth tone in this audio has a frequency of 440 Hz.

Let us see why such a relation between perceived change in frequency, actual frequency and actual change in frequency implies that our perception of pitch is logarithmic.

Let dp be the perceived change in frequency. Let df be the actual change in frequency. Let f be the frequency at which the change occurs. As per the discussion above,

dp ∝ df / f ⇒ dp = k · df / f, where k is a constant

Let us integrate both sides of the equation.

dp = k · df / f ⇒ p = k · ln f + c, where c is a constant

So, here we can see that the perceived pitch is directly proportional to the logarithm of the actual frequency. Now if we represent the first actual frequency as f1st, the second one as f2nd and the corresponding perceived changes in pitch as p1st and p2nd, the perceived change in pitch is:

Δp = p2nd - p1st = (k · ln f2nd + c) - (k · ln f1st + c) = k · ln f2nd - k · ln f1st = k · ln (f2nd/f1st)

So, when you hear a change of 10 Hz at 100 Hz, you perceive a change in pitch of k · ln(110/100) = 0.095k. However, when you hear the same change in frequency at 400 Hz, you perceive a change in pitch of only k · ln(410/400) = 0.024k.

I tried to do a similar experiment with colours: http://susam.in/downloads/files/weber-fechner/color.html. Just like the sound experiment, here the intensity of blue increases from 20 to 40 in the first change and 200 to 220 in the second change. However, I don't think the perceived change in brightness in the first instance appears to be greater than that of the second one. I find both the changes to be almost equal. So, does Weber-Fechner law not work here? The Wikipedia article on Weber-Fechner law mentions that the eye senses brightness approximately logarithmically. Is there a flaw in my experiment?

For a moment, I thought that perhaps, the intensity of blue I am specifying in the RGB code is not directly proportional to the brightness of the color. But the formula GIMP uses to calculate the grayscale brightness from a color image implies that the brightness is directly proportional to the intensity of blue we specify in the RGB code. Or is it that the intensity we specify in the RGB code is already directly proportional to the logarithm of the brightness?

A related post: Listening to superimposed waves.