Pages

Saturday, September 14, 2019

Squishbacks


My office is built into the side of a hill, and several times while waiting for my bus, I've seen bicyclists rocketing down at tremendous speed. I was imagining they would burn through their brakes quickly, and wondered if there were a better way to limit your speed on a hill. Switchbacks used by hikers came to mind – Instead of taking a direct route up a mountain, trails wind back and forth, which reduces the slope. I was curious if a similar method could be used to slow down.

If we ignore air/rolling resistance, we can use conservation of energy to relate the drop in height to the total velocity gained:
For a road of slope m, we can set up a differential equation relating this total velocity to the individual forward, sideways, and vertical velocities:
Suppose we want to maintain a constant forward velocity, and so any extra gets put into the side-to-side motion. Then we can get the total forward travel just by multiplying the velocity by t, and we can write the sideways speed as
The trouble with this strategy is that as you go downhill, your total velocity is increasing, but your forward velocity is constant. That means proportionally, you'll be traveling far faster sideways than the direction you're planning to go. I picked a 30% slope and 10 m/s forward speed to plug into the equation above:
After only about 10 seconds, 90% of your speed is perpendicular to the direction you want to go! Now that doesn't mean you'll never get to your destination – That speed is fixed, remember. Because we ignored resistive forces, your total velocity keeps increasing. I suppose it may be better to stick with the brakes – Not only does this method still have you going at uncomfortably high velocities, you'll also take a lot longer to get where you're going.

Saturday, September 7, 2019

CERN SMASH!

I missed posting last week because I was in Geneva visiting CERN! Marika was flying home via the city, and my brilliant mother-in-law suggested we take a tour of the facility. I thought I'd take this week to explain a bit about how the collider works.

The first CERN particle collider
CERN is the European Organization for Nuclear Research, but the umbrella of "nuclear research" extends farther than you may think. When researchers needed a way to share data between sites over the world, they developed a communication network between their computers that became the World Wide Web. We actually saw the very first web server, kept in a dimly lit room (its natural habitat), so I couldn't get a picture.

The main thing CERN is known for though is the Large Hadron Collider. I talked a bit about particle accelerators in my second-ever post on this blog, but that was just about getting particles up to a certain speed, not colliding them with other particles (aside from my brain).

The purpose of particle colliders is to create new particles by smashing together pairs of other particles. The key lies in what is probably the most famous equation in science:
This equation connects energy to mass, but energy comes in many forms. In this case, we give the initial particles kinetic energy by accelerating them. When they collide, that can be converted into mass energy to create higher mass particles.

The various particles in the Standard Model each have different masses, with the Higgs Boson being the heaviest. Heavier particles have more energy, which means we need faster initial particles to produce them. We can modify the equation above to include the velocity:
As the velocity, v, gets closer to the speed of light, c, the energy gets bigger and bigger. This is why you can never get up to light-speed: You'd need infinite energy. By accelerating lighter particles though, we can hope to create heavier ones.

While the Standard Model is now complete, there are other theories to go beyond it. The LHC is currently being upgraded to handle even higher energies in the hopes of confirming or refuting these theories. I loved seeing all the bits of science history they have there, and I encourage anyone passing through Geneva to go take a look!

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!