Saturday, August 24, 2019

Strung Out

This is another idea from my list, and I have absolutely no memory of the source, aside from a casual interest in computer-generated sound and music: The Karplus-Strong algorithm. This is a technique for generating the sound of a plucked string, using entirely electronics, no actual strings required! Before we get into the algorithm though, we should go over some background:

What is sound?
Sound is a wave made up of pockets of higher- and lower-pressure air (or other substances). These pockets of pressure excite your eardrums in different ways that your brain interprets as sound. A musical note has a pitch, which is a specific frequency of high/low pressure changes.

How does a computer make sound?
A computer speaker uses magnets to change electricity into sound:
By Svjo - Own work, CC BY-SA 3.0, Link
The yellow coil is a wire that the computer can run current through. This creates a magnetic field, which moves the magnet (2) in the middle of the coil. The magnet is attached to a diaphragm (4) which compresses and expands the air in front of it to make sound waves.

What do we put into the speaker to get a note?
This is where the algorithm comes in. A pitch is a specific frequency, so as long as we repeat whatever we're putting into the speaker, we'll get some kind of note. If you remember your math classes, a sine wave might come to mind:
Unfortunately, as any Physics Lab instructor can tell you, pure sine tones aren't the most melodious to listen to:

Not surprisingly, it sounds a bit like a telephone tone, another form of computer-generated sound, designed to be heard by a computer.

Musical instruments sound different even when playing the same pitch because of the harmonics they include. There's a base frequency, like the sine wave above, but then there are many others that add color to the sound. This is where the Karplus-Strong algorithm comes in. We want a way to systematically create a range of frequencies associated with a single base frequency.

I don't want to get too deep into how the algorithm works – for that you can read the Wikipedia page I linked above, or take a look at the code I used to make these sounds. I will, however, try to summarize the concept.

We start with a list of values – mostly zeros, but we initialize things with some random noise at the beginning:
We then take the first value and output it. At the same time, we combine it with the second:
We put the combined value at the back, and move everything forward:
It's a simple method, but I was stunned by the quality of the sound I got out of it:

I also plotted some frames of the buffer to see what was going on:
You can see the burst of noise at the beginning, and then a damping sinusoidal wave.

I was curious what kinds of tones I could get by playing around with the filtering pattern. First I tried simply extending from 2 bins to 5:

Then I decided to go nuts and try a sinusoid filter:

The sound is even worse than the pure sine, but the waveform is really interesting:

It's a little difficult to see, but the initial noise manages to continue propagating through, as the sine pattern gradually asserts itself.

The thing I love most about Physics is how simple models can still give realistic results, and this is a perfect example. I wrote the code above in less than an hour, with no specialized knowledge about sound synthesis, yet the result sounds exactly like a plucked string. As always, I encourage the tech-minded among you to look at the code, and come up with some interesting sounds for yourself!

Friday, August 16, 2019

The Rays, They Raineth Every Day

Another great question from Papou: How many different particles from beyond our Universe reach the earth and penetrate our human bodies? What particles are they and where did they emanate from?

There's an easy answer to the question as written, since "the Universe" usually refers to everything that has or ever will exist: None! That's not very satisfying though, so instead, let's look at some of the particles that arrive on Earth from space.

Solar Neutrinos
Starting off close to home, aside from light, the Sun also puts out about 9 x 10^28 neutrinos per second that stream through the Earth. Neutrinos only rarely interact with other matter, which should relax you about the sheer number hitting us right now. My friend Kevin studies these neutrinos, and the only way to detect them is to burrow deep into the Earth, to filter out other particles, and then build a huge tank of ultra-pure water surrounded by photodetectors. Now and then, a neutrino will interact with one of the water molecules and emit a flash of light. There are several types of neutrino, and Kevin studies how these different types change into each other in a process called oscillation.

Cosmic Rays
Moving outside the Solar System now, we also get cosmic rays from distant objects. These are massive particles, like protons or electrons, that hit the atmosphere at high speed. Unlike neutrinos, these do interact with the molecules in the atmosphere, and cause a cascade of reactions, similar to what happens in a particle collider:
The main source of these cosmic rays is believed to be supernovae. When stars explode, they send out particles in all directions at high speed. These particles can travel a long distance, since space is big, and there's not a lot to run into. When they reach Earth, they're going so fast that entering the atmosphere produces Cherenkov radiation. This type of radiation occurs when a massive particle enters a substance faster than light can travel in that substance. Massive particles cannot go faster than light in a vacuum, but light can go much slower in other materials. This type of radiation is analogous to a sonic boom. I actually experienced Cherenkov radiation as a static fuzz over my vision during my proton radiation treatments.

Gamma Rays
The cosmic rays I just described are high-energy massive particles, but there are also high-energy massless photons that hit the Earth. These are referred to as gamma rays, due to the symbol for photons used in particle physics, 𝛾. In the 1960s, the US launched the Vela satellites to look for gamma rays coming not from space, but the surface of the Earth. They hoped to use the satellites to monitor Russian nuclear tests, which also produce gamma rays, but were surprised to find signals coming from space instead. When the LIGO/Virgo collaborations detected a neutron star merger in 2017, scientists discovered it was correlated with a gamma ray burst in the same direction, suggesting the burst was produced in the collision.

Shields Up!
All this talk of high-energy particles hitting Earth might have you a bit worried. Lucky for us, we have some defenses against them. The ozone layer absorbs most of the UV light from the Sun, and the Earth's magnetic field protects us from most charged particles. Astronauts who spend time outside these protective fields though, are exposed to numerous risks from exposure to particles like these. NASA has studied the effects of space flight by comparing the twins, Mark and Scott Kelly, and while some differences are temporary, the increased radiation exposure can cause permanent DNA damage. We should be glad for the protections our planet offers us, and do what we can to protect it in turn!

Sunday, August 11, 2019


Last weekend, Marika and I went to Fête du Lac, the largest fireworks display in Europe, held over the beautiful lake. We went for the cheap seats, which didn't include seats. Most people brought blankets, but Marika found a great waterproof fold-up mat for us:
The problem came when we went to fold it back up at the end of the evening: How do you make sure the handles line up again? I managed to bumble my way to a solution, I'm sure due to years of experience doing origami with my mother, but it got me thinking about how many ways you can fold something.

This is called the Map-Folding Problem, and there is so far no known way to predict the number of ways to fold a map, aside from trying every solution. The main thing I was curious about was what a particular folding looked like once unfolded – the pattern of mountains and valleys. Naturally, I wrote a Python script to figure it out:

Here we're considering a 3 x 3 grid, which needs 2 folds in each direction. The color of the lines indicates the direction of the fold: red for valley and blue for mountain. We make each fold at position 1, but in the first image we alternate directions, and in the second we go twice in one direction, and twice in the other.

Looking at the unfolded images, it's reasonably easy to spot where each fold happens, but as the number of folds increases, the complexity grows rapidly. So far the result is only known up to 7 x 7: 129950723279272! At that point, your best option might be to crumple the map (or yourself) into a ball, and enjoy some fireworks:

Saturday, August 3, 2019

See Spot. See Spot Cool.

Another question from the ever-curious Papou [paraphrased]: I've been reading about the cycle of sunspot activity, and how some believe it connects to climate change. What are your thoughts on this?

Let's start off by discussing sunspots. The sun is essentially a big ball of plasma, a state of matter that's particularly good at holding electromagnetic fields. Under certain circumstances, some magnetic field lines in the sun will bunch together, and change the flow of particles around a spot. This causes the spot to cool enough to appear dark:
Getty Images via Scientific American
In the 1890s, an astronomer couple named Annie and Edward Maunder noticed that there was an unusually low number of sunspots during the years 1645 to 1715, which came to be known as the Maunder Minimum. That period is also known as the Little Ice Age*, due to the unusually cold weather. Some people draw a link between these two, and suggest that sunspot activity is responsible for changes in global climate.

In cases like this, it's important to remember the science adage, "correlation does not imply causation." This means that just because two quantities change in a similar way, it does not mean that one causes the other. Obviously, if one thing causes another, they will be correlated, but you need more than that to prove causation: You need to explain how they're linked, and show that that explanation is backed up by data.

Sunspots actually fail on both counts: Sunspots are dark because they're cooler than the rest of the sun. The Little Ice Age, though, happened during a minimum in the number of sunspots, and tracking the temperature through time shows little correlation:
While it's important to consider alternate theories to popular beliefs, it's also important to discard them when they are shown to be inaccurate. As I discussed several months ago, I am not an expert in climate science, so I defer to the vast majority who identify CO2 emissions as the leading cause.

*Nifty cultural note unrelated to Physics: Charles Dickens is largely credited with giving us our collective image of a white Christmas through his story A Christmas Carol. Christmases that include snow, however, are quite rare, and it's likely that Dickens only imagined it this way because he grew up at the end of the Little Ice Age, where they were more common.