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

Nov 24, 2019 · 2 min read

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…

Written by

## Prof Bill Buchanan OBE

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.

Written by

## Prof Bill Buchanan OBE

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.