Monthly Archives: December 2016

The limits of Human Hearing II

Yesterday, we looked at sounds near the bottom of human hearing and found a lot of water. Today, we’ll look upwards. Who knows what elements we’ll find?

As you may recall, we started with a sine wave at 100Hz:

To me, this sounds almost like your canonical computer generated sound, something you might hear in a hearing test, or at the Science Center in the 1980s.

Let’s go up an octave to 200Hz:

Same kind of feel, a little higher, feels a little louder (probably again because of ‘equal-loudness contours‘).

Now, 400Hz:

This is starting to get into painful territory for me (at least through headphones).

800Hz:

This is starting to sound like an alarm.

Warning: We’re now getting into sounds that might start hurting or make your ears ring. I recommend that if you’re going to play these, that you play them at low volume first, and step them up in volume slowly.

1600Hz:

This is most definitely an alarm sound. About 2.5 octaves above middle C, it is above the normal soprano range, and therefore might reasonably be normally interpreted as an exclamation/scream, or alarm by early humans.

3200Hz:

An alarm, or medical beep.

6400Hz:

Many people would find this painful. I don’t think pitches this high are used for very much at all[1]. Probably only in movies to show a painful sound. (My right ear rang briefly after playing this sound.) It also sounds like we’re starting to reach the limitations of 44100Hz[2] sampling, as you will probably be able to hear the distortion in this clip.

12800Hz:

This is getting into the range of where humans might stop being able to hear things. It sounds (to me) like something out of place, or ear ringing (which is happening right now after playing it)[3].

25600Hz:

We’re now probably above what we can reproduce with 44,100Hz sampling. This sound seems to be inaudible at normal volumes, but when you turn it up, you’ll hear something very high-pitched, probably a lower (but still high) pitch caused by aliasing.

51200Hz:

We should not be able to hear anything here, due to it being above the sampling rate. I hear it as a loud sound a major third above the (quieter) 12800Hz .wav above. This suggests that the aliasing is producing a pitch of around 16,000Hz, which is about 1/3, or an octave and a fifth lower than the 51200 we attempted to make. (It still hurts, though.)

Next time, we’ll look at some different-shaped waveforms. Stay intuned!

[1]We’re talking about the fundamental frequency in a constellation of frequencies. I’m sure that 6400Hz occurs often, but there are generally lower pitches which it helps ‘fill out’.

[2]44,100Hz is one of the standard sampling rates, apparently chosen for Compact Discs by Sony in the Red Book standard. The article also mentions that 44,100 was chosen for Nyquist Sampling reasons to be >2x the commonly accepted threshold of human hearing (20kHz), plus a guard band for low-pass filtering. Also, for those of you who love prime factors and easy divisibility, 44100 = 2*2*3*3*5*5*7*7.

[3]Is it sympathetic? Is it because the ears or processing mechanisms are now expecting it? Are guarding against it?

The limits of Human Hearing I

Now that we’ve generated a .wav file from our sine wave, let’s take a look at some of the limitations of music as it’s written for the human ear[1].

We’ll start with the low end of human perception.

As you may recall, last time, we made a 100Hz sine wave:

This is near the bottom of what most humans can hear (and close to the bottom of what I can sing), but there’s still plenty of room to explore.

One octave down, we have 50Hz:

This is as low as I can comfortably hear (and sing!). Below this, for various reasons, things get much quieter[2] and more difficult to produce.

25Hz:

At normal volumes (halfway up on my laptop) sounds quite soft, but still audible. At louder volumes, it sounds like something you might hear in the 8-bit audio of a game from the early ’90s, perhaps in a dungeon to tell you something is oozing out of the wall.

12.5Hz:

To me, this is inaudible at normal volumes. At high volumes, it feels like what gargling would sound like in an 8-bit world.

6.25Hz:

At normal volumes, still inaudible. At high volumes, almost like water.

3.125Hz:

If the previous one sounded almost like water, this is the real deal. Still inaudible (as you would expect) at normal volumes.

1.0675Hz:

I totally did not expect to go this low in frequency. This sounds perhaps even more like water at high volumes. I wonder why all of these do. Maybe it’s some other effect unrelated to the actual frequency of the sinewave, perhaps waves (and water) do actually make sounds at such low frequencies, or those low frequencies make secondary effects/harmonics at high amplitudes.

Next time, we’ll look at the high end of human hearing. Stay tuned[3]!

[1]I’m leaving out discussion of making music to be felt by other parts of the body, although that is probably a large part of why dance clubs are so popular. We could also talk about different species, using devices, perhaps mediated human listening to music, but that is outside of scope.

[2]I had assumed it had to do with the amount of energy being transmitted being non-linear with the frequency, but apparently it has more to do with human hearing. ‘Equal-loudness contours‘ will show you the way.

[3]Hee.

If you wish to make a song from scratch, you must first Invent the Universe…

To write some music, you must first invent some instruments. To do this, one might start with a simple sine wave, then do modulations and superpositions to make various ‘instruments’.

To this end, I did a little bit of research (thanks, soledadpeandes!), and put/cribbed together some python code to make arbitrary .wav files:
# Written 2016-12-26, with special thanks to:
# https://soledadpenades.com/2009/10/29/fastest-way-to-generate-wav-files-in-python-using-the-wave-module/

import wave
import struct
import math

SAMPLING_RATE = 44100
WAV_FILE_LEN = SAMPLING_RATE * 1 # 44.1KHz sampling rate, 5 seconds
MAX_AMP = 32767
CORR_FACTOR = 10
SIN_WAV_FREQ = 100 * CORR_FACTOR # Sine wave frequency, in Hz*10 for some reason, 1000 gives 100Hz

output_file = wave.open('test.wav', 'w')
output_file.setparams((2, 2, 44100, 0, 'NONE', 'not compressed'))

for i in range (0,WAV_FILE_LEN):

data = MAX_AMP*math.sin(i*float(SIN_WAV_FREQ)/float(SAMPLING_RATE)/(math.pi/float(2)))
print data
packed_data = struct.pack('h', data)
output_file.writeframes(packed_data)
output_file.writeframes(packed_data)

output_file.close

For those who are curious, this generates a 100Hz sine wave: .

Next up, some experimentation with different pitches, perhaps different timbres. Stay tuned*!

*Also 100Hz.

Electoral Reform in Canada: What are the Options?

Last time, we talked about some of the things we might want in an electoral/voting system:

Having a say:
– Each vote should have the highest probability possible of changing the representation of the House of Commons

Quick:
– The public should know the results within hours of the polls closing.

Fair:
– Political parties should not be significantly inconvenienced by the electoral system for not having money.
– Any barriers to entry should be reasonable (number of candidates to be a registered party, number of votes to get deposits back, percentage of popular vote to qualify to get seats, etc…)
– The system should not unduly give power to very small groups (49/49/2 split, the 49 and 2 have equal power).
– The system should be ‘simple enough’ for people to understand. Currently, people vote for one person, one party with the same vote. A similar system being successfully used elsewhere in the world is a reasonable way to determine ‘simple enough’.

Representative:
– There are a number of ways to be representative:
– Geographically
– Representation of party by population
– Minority groups
– Diversity of opinions

Resistant to cheating:
– Secret ballot to reduce intimidation and coercion as factors
– Reasonable voter ID laws to increase voter turnout while keeping the risk of personation low.
– Distributed counting makes the current system quite resistant to cheating. One would have to mess with the voting tally computers in real-time to change this. The fact that there is an anonymous paper record of every vote cast in the ballot boxes is also an important check on this system.

As the Canadian government has (very likely) decided that whatever the parliamentary committee has decided will go to a referendum, I’m going to add one more criterion:

– Able to pass a Canadian referendum

For many people, the choice of voting system is not clear, as you can see by this table.

For options, I’ll start with the options considered by the New Zealand Commission on the Electoral System[1]:
– First-past-the-post
– Single transferable vote
– Supplementary Member
– Alternative Vote
– Mixed member proportional.

First-past-the-post:

This is the current system in Canada. The country is divided up into ridings (currently 338) of approximately equal population (generally geographically larger ridings have less population per riding.

Advantages:
– Simple
– What we’re currently doing

Disadvantages:
– Vote splitting by riding (candidates can win a riding with less than 30% of the vote)
– Vote splitting across the country (a party can win a majority government with less than 40% of the popular vote)

Single transferable vote:

Single Transferable Vote (STV) is used for elections in Ireland, Malta, much of Australia, and various other parts of the English-speaking world.

Basically, the country or region is divided into single-[2] or multi-member ridings. In each of these ridings, voters rank the candidates on their ballots. Each candidate who receives more votes than the number required to be elected is elected, and all of their ‘extra’ votes are passed on to other candidates proportionally. If there are no candidates who have the number of votes required to be elected, the candidate with the fewest number of votes is eliminated and their votes are redistributed as above. Example here.

Advantages:
– More proportional representation than First-past-the-post
– ‘wasted votes’ guaranteed to be less than (1/(# of seats per riding)*100%), or for example <33% for a riding with three possible elected candidates Disadvantages: - You have to have all of the votes in one place to count them - Ridings must have many candidates per riding to reduce the number of 'wasted votes' Supplementary Member or ‘Parallel Voting’:

Technically, Supplementary Member Voting or Parallel Voting is defined as combining any two (or more) voting systems in parallel. Most often, it is used to combine some proportionality with a First-past-the-post system. Voters would vote twice, once for their local riding, and once for a proportional slate of candidates. These votes would be separate, leading to the results being more proportional, but not fully proportional.

Advantages:
– More proportional than First-past-the-post

Disadvantages:
– Not really that proportional
– More complicated than First-past-the-post

Alternative Vote or ‘Instant-runoff voting’:

Instant-runoff voting is used in various elections in Australia, India, Ireland, Papua New Guinea, and various local elections around the world, as well as by some political parties.

Similar to Single Transferable Voting, voters rank candidates in order on their ballot. If one candidate has a majority of the votes, that candidate is elected. If no candidates have a majority of the votes, candidates are eliminated and their votes are redistributed according the the voters’ preferences until one candidate receives a majority of the vote

Advantages:
– More votes count than in First-past-the-post, as no candidate can win without the plurality of the votes in a riding.
– ‘Vote splitting’ is much less of an issue, as parties or candidates who would normally ‘split’ votes would tend to be likely to be the second choice of those voters.

Disadvantages:
– You have to have all of the votes in one place to count them
– Up to half of the votes in each riding can be ‘wasted’

Mixed Member Proportional Voting or ‘Additional Member System Voting’:

Mixed Member Proportional Voting is used in Germany and various sub regions of the United Kingdom. It was the subject of the failed Ontario referendum of 2007. In most implementations, voters have two votes. One vote for a local candidate, and one vote for a party. Local candidates are elected using a First-past-the-post system. There are an additional number of representatives elected to bring the results in line with the popular vote. These additional representatives are generally based on party lists, but some proposals have them selected on a more regional basis, to allow better regional representation.

Advantages:
– In most cases, as proportional as electoral systems get
– Includes a strong local representation element
– Should be easy to describe to the public

Disadvantages:
– Already failed one referendum in Canada
Party list seats are susceptible to collusion

Thanks for reading! Next time, we’ll go more in depth, and start to figure out which of these we might prefer. Stay tuned!

[1]New Zealand being a Westminister System country which had recent (1992,1993) referenda on changing its voting system from First-past-the-post.

[2]If there is only one seat per riding, STV is the same as ‘Instant Runoff Voting‘.