Photo by Jefferson Santos on Unsplash

Our World Is Made More Beautiful By Harmonics (and Python)

What makes a guitar sound nice? Is it the chords, the key or the notes that are played? Not quite, as an A note on its own is rather boring. If you have ever heard an A note on an audio generator it sounds rather dull and plain. In fact it is just a 440 Hz sine wave [here], with a single frequency in the frequency domain:

So why does a guitar sound so interesting? Well it produces harmonics of the fundamental frequency, such as at three times the fundamental frequency, and five times the fundamental frequency. Our ear generally likes these odd harmonics, and a well designed guitar will make sure that that these are well supporte. In the following we have a wave which has a 3rd harmonic with 40% of the amplitude of the fundamental and a 5th harmonic with 20% of the amplitude of the fundamental [here]. We see a more characteristic waveform for sound, and also see three spikes for the frequencies in the frequency domain:

In Python, we can easily convert from the time domain into the frequency domain using a FFT (Fast Fourier Transform) and using mighty Numpy (np) library:

Y = np.fft.fft(y)/n # fft computing and normalization

In Python, we can also use the matplotlib library, too, in order to illustrate the time and the frequency domain plots. And, so, here is the full code. I have used a 5 Hz fundamental wave, and which gives a period of 0.2 seconds:

If you are interested, here is a demo of analysing signals in Python [tutorial]:

and with some theory:

Go do some Python. It is a great tool kit for learning. If your kids are learning maths, it is a great playground for coding and learning. For you, just go learn Python!

ASecuritySite: When Bob Met Alice

This publication brings together interesting articles…

Prof Bill Buchanan OBE

Written by

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

ASecuritySite: When Bob Met Alice

This publication brings together interesting articles related to cyber security.

Prof Bill Buchanan OBE

Written by

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

ASecuritySite: When Bob Met Alice

This publication brings together interesting articles related to cyber security.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store