
Breaking a Wine Glass in Python by Detecting the Resonant Frequency - burningion
https://www.makeartwithpython.com/blog/break-glass-with-resonant-frequency/
======
ChuckMcM
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](https://www.youtube.com/watch?v=IZD8ffPwXRo),
and
[https://www.youtube.com/watch?v=7xODgR2FEKo](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.

~~~
tzs
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...](https://pubs.geoscienceworld.org/ssa/bssa/article-
abstract/99/2A/626/342074)

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

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

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

[5] [http://earthquake-
eng.usc.edu/ECEES_STS-E10/Clinton_BSSA_200...](http://earthquake-
eng.usc.edu/ECEES_STS-E10/Clinton_BSSA_2006.pdf)

~~~
ouid
"something that resonates" is a pretty weak condition.

------
Tomminn
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.

~~~
maxerickson
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:

[https://www.youtube.com/watch?v=dMhrF-
LvfUk](https://www.youtube.com/watch?v=dMhrF-LvfUk)

~~~
Tomminn
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;)

~~~
dec0dedab0de
Especially since A=440 is arbitrary to begin with.

~~~
olympus
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.

------
js2
Semi-related discussion 4 months ago:

[https://news.ycombinator.com/item?id=15667096](https://news.ycombinator.com/item?id=15667096)

------
baobrien
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.

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

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

[https://docs.scipy.org/doc/scipy/reference/generated/scipy.s...](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.freqz.html)

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

~~~
pletnes
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.

------
goldenkey
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.

~~~
tripzilch
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.

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

~~~
SlowRobotAhead
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.

~~~
mrlala
>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.

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

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

------
the_cat_kittles
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](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!

~~~
nurettin
"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.

~~~
jsjohnst
“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?

~~~
nurettin
here you go: [http://blog.nurett.in/post/171958522813/python3-for-
frustrat...](http://blog.nurett.in/post/171958522813/python3-for-frustrated-
rubyists)

~~~
abhirag
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](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](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/](http://www.poodr.com/)) and the two languages have a
lot in common if you just keep an open mind about it :)

~~~
nurettin
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)

------
michaelfeathers
Obligatory.

[https://news.ycombinator.com/item?id=11189688](https://news.ycombinator.com/item?id=11189688)

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

