Hacker News new | past | comments | ask | show | jobs | submit login
Breaking a Wine Glass in Python by Detecting the Resonant Frequency (makeartwithpython.com)
375 points by burningion on Mar 17, 2018 | hide | past | web | favorite | 48 comments

Resonance is an amazing thing. I was fixated on it for a while because it was something that fascinated Tesla. There was a story where he attaches a small hammer to a building which is tapping slowly and it shakes the building to its foundations. The Mythbusters have done a couple of shows on it as well (https://www.youtube.com/watch?v=IZD8ffPwXRo, and https://www.youtube.com/watch?v=7xODgR2FEKo)

Things I learned were that the crystal (and steel) structure are important because every bit of compliance in the system absorbs energy and turns it into heat rather than reflecting it back into the structure. Bricks work too if they are hard fired.

Finding the exact resonant frequency can be difficult as it can change as the system begins to vibrate. Sometimes the harmonics are better than the fundamental frequency. If I were doing this today I'd probably clips a strain gauge to the material and use a feedback loop to localize to the peak energy absorption frequency.

They used to do a demo for the introductory mechanical engineering class at Caltech where they got the 9 story Millikan Library noticeably moving by having something vibrating on the roof at the building's resonant frequency.

That library has long been used for research and experiments involving resonance. The seismologists and structural engineers have had it full of instruments for 50 years and been studying how its resonances change periodically in response to weather and other natural cycles, and how they change permanently after earthquakes, and they have used shaking it to study wave propagation.

Apparently all you need is something that is big, resonates, and is coupled to the ground and you can do some fun science.

Some papers:

"Soil-Structure System Identification of Millikan Library North–South Response during Four Earthquakes (1970–2002): What Caused the Observed Wandering of the System Frequencies?" [1]

"The Millikan shaking experiments and high-frequency seismic wave propagation in Southern California" [2]

"Variations in the Natural Frequencies of Millikan Library Caused by Weather and Small Earthquakes" [3]

"Results of Millikan Library Forced Vibration Testing" [4]

"The Observed Wander of the Natural Frequencies in a Structure" [5]

[1] https://pubs.geoscienceworld.org/ssa/bssa/article-abstract/9...

[2] https://www.scec.org/publication/1908

[3] https://ascelibrary.org/doi/abs/10.1061/40753%28171%2990

[4] https://authors.library.caltech.edu/26542/

[5] http://earthquake-eng.usc.edu/ECEES_STS-E10/Clinton_BSSA_200...

"something that resonates" is a pretty weak condition.

With sheet piling they sometimes use the resonance of the sheets to let them vibrate so they will sink into the mud.

This is sometimes needed next to old buildings where hammering will cause damage.

A laser would work well too, that way you don’t damp the resonance.

The famous Tesla Coil is a resonating transformer, too.

This cut does a good job for buildings: https://www.youtube.com/watch?v=SFBV2UzsB3A

Why are you sending us to a “Dub Step” audio track titled “An ten nae ft Buccaneer Warning”?

Did you listen to it?

It has a section, where the frequency drops to subsonic at constant volume. So you can feel resonant frequencies.

I noticed an interesting resonance just yesterday on my guitar. You can actually tune a guitar by playing, for example, an A note on the E string repeatedly, and moving the tuning pegs on the A string until the A string starts vibrating.

This is kind of hard to do using just the visuals, as you run out of hands unless you play and fret the string with the same hand. But it works really nicely if you try to find the note by ear, and then use visual resonance as confirmation that you're right. Makes tuning pretty fun.

That'll tune the one string to the other, but not necessarily bring the guitar into tune. This guy goes through a bunch of other combinations:


I'd always have this argument with the rhythm guitarist of my band on stage. He'd stop and tune by ear to himself by harmonics

1) You're annoying the audience. Stop.

2) You're only tuning to yourself, not the band. Please use your tuning pedal.

Yeah, but that's always the best you can do without an external note. And if there are no external notes around, you could argue it's all that matters;)

Especially since A=440 is arbitrary to begin with.

It starts out arbitrary but becomes useful once everyone agrees with it, like measuring distance in meters- which has gone through several definitions, none of which make much sense in terms of being based on a natural constant and using a nice round numbers as a coefficient.

If four instruments are following the standard and one is a bit flat because "A-440 Hz is arbitrary" then the whole band sounds like a mess.

Sometimes people intentionally want the effect of a guitar that's in tune relative to itself (which provides harmonies and aesthetic value) but not necessarily on the normal scale or relative to other instruments.

But you'll end up with a Pyhtogorean temperament instead of an Equal one.

This is generally true of tuning an instrument. It's how I've always tuned guitar.

In the case of guitar you only need a starting E tone and can figure out the rest by yourself.

In the case of an orchestra or concert band, everyone plays at once during tuning and you use the dissonance as a guide. Once there is no dissonance, everyone is in tune.

This is a very common way to tune a violin but only works if you have a good reference source or excellent pitch.

do you know how to tune using harmonics? if not, learn it, it is accurate and geeky

Accurate. Too accurate. You end up with your strings in perfect 4ths instead of equal tempered fourths. That’s just under 2 cents off, but if you tuned all adjacent pairs it adds up.

Be careful not to train your ears to hear the difference. Guitars playing chords are maddening collections of compromises and you will find yourself spiraling into sweetened tunings and fiddling with intonation instead of playing and enjoying music. Someday when you are adjusting your microtonal frets between songs, remember I warned you.

believe it or not, its not that accurate because of the imperfect tuning ratios of even tempered scale. i think checking 4ths and 5ths of adjacent strings is really the way to go, since those are the ones that sound really bad when out of tune. if you really want to get in to the weeds of tuning on a guitar, martin taylor touches on some more of the complexities here: https://m.youtube.com/watch?v=Dl3mcHixAKM

Semi-related discussion 4 months ago:


Couldn't you figure out the resonant frequency automatically by hitting the glass with a few impulses from the speaker and looking at the response? That'd be a fun signal processing exercise.

I’m not a sound expert, but I’m curious how you think this would work?

Applying fourier transform to impulse response results in the frequency response:


I think this would work only if the system in question is reasonably linear though, which wine glass might not be (?)

Technically speaking, you don’t need to know the frequency response in detail, or whether it’s exactly linear. If the glass «sings» at a given frequency after being whacked by a short impulse, that’s a resonant frequency.

When the glass starts resonating, it should start prouducing sound too, so you should be able to hear two frequencies as you get close to the right frequency — I think. (Not a sound expert either)

Was a bit dissapointed. Thought he was going to do an audio sweep and use ML on a video feed to detect the resonant frequency and break the glass as fast as possible.

I agree it would have been cooler if he did an autodetection sweep (or the impulse response thing mentioned upthreads), but not disappointingly so. However I would have been disappointed if he used ML for the detection. Some basic DSP would suffice and be much more accurate without needing a days worth of training on a powerful video card.

What struck me was a different project every day for 50 days. lovely way to spend your time

IDK. For me that would be training myself to put hacky poorly considered code together as fast as possible.

I can already do that, but it’s not a good habit.

>but it’s not a good habit

Being able to get things done is a good habit.

There's of course a balance somewhere in the middle, but doing 50 projects in 50 days and having to work quick and write code that "works" is certainly a valuable skill.

So if he builds a big one can he knock down bridges?

Hacker News paydirt! Good read, cool programming. :)

fun project! if you arent married to python, or the idea of writing a bunch of superfluous code (:P) fft'ing a sound is pretty trivial, and creating a sound at that frequency is also trivial from command line. i google for 15 seconds, looks like this library https://aubio.org/manual/latest/cli.html would work fine with something like

    aubio notes -r $(aubio pitch myfile.wav)
would probably do it. i love python as much as the next person, but sometimes... ah well, cool project anyway!

As much as I’d likely end up using some sort of scripting language for something like this, being able to do it via command line is always lovely.

"doing X in python" titles are a recurring theme in HN. I don't care much about the language, especially because of silly syntax like explicit self on methods (oh yeah, they have the "zen philosophy" of explicit vs implicit where every other thing in the language is implicit except this) and obviously broken tooling that installs an old version of pip when you create a virtual environment.

“complaining about X” when X isn’t your preferred tool of choice also sadly seems to be a recurring theme on HN comments. Where’s your post about doing something similar in your tool of choice?

I have no intention of starting or getting into a flame war between Ruby and Python, both are great languages but I can help with the Python tooling a bit. The Python equivalent of rvm is pyenv (https://github.com/pyenv/pyenv/blob/master/README.md) and to install dependencies and handle virtual environments after that you can use pipenv (https://github.com/pypa/pipenv). Both of them together will get you almost similar experience to the Ruby tooling example you ended the post with.

I love why the lucky stiff's writing, I love POODR (http://www.poodr.com/) and the two languages have a lot in common if you just keep an open mind about it :)

I do appreciate the effort you've put into this response, unlike parent. Well done. Next time I have to do something in python, I will try pyenv and pipenv (and maybe write about it, too)

Exactly what I expected as a response. Thank you for confirming my suspicion!

You provide so much value. Definitely an MVP hackernews user.

Why should I spend my valuable time to help you when you literally spend no time to help yourself and instead blame tools for your inability to use them? Reread your posts in this thread and your blog post and show me where there’s any sign that wouldn’t be a lost cause effort.

Here you go:

>> I do appreciate the effort you've put into this response, unlike parent. Well done

I'm happy you provided me with standard HN comments, though. Well done, to you, too. Very VIP HN.

that's great! but what's it to do with python ?

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact