Skip to main content

Time series analysis with the Fourier transform, explained through music

What the frequency representation of a note and a chord shows, and how the same tool detects heart rate or recurring cycles in sales and demand.

A musical note is air vibrating at a specific frequency: the reference A vibrates 440 times per second. Starting from that example, this article explains the difference between viewing a signal over time and viewing it by frequency, what the Fourier transform reveals about a chord, and how the same approach applies to ECGs and to sales or demand cycles.

This article introduces a very useful concept for processing anything that can be read as a time series: the frequency-domain representation. To make it more approachable and intuitive, we will see how the tool applies to a sound wave and how it helps us interpret that wave musically. At the end, the same idea is applied to two data science cases: heart rate and recurring cycles in sales or demand.

Before getting into what a frequency representation is, let’s go over a few concepts that explain what a sound wave is, what is worth extracting from it in a musical context, and how those features show up.

How sound is produced

Most musical instruments produce sound by making the air vibrate, one way or another. A guitar (and string instruments in general) does it by making its strings vibrate; a trumpet (and most wind instruments), by making the air inside it vibrate; and even percussion instruments do it, by making their membrane vibrate.

Making the air vibrate means causing small variations (oscillations) in air pressure, something like compressing and expanding the air very quickly. So sound is a wave that travels through the air by means of these oscillations, which our ear ultimately picks up by detecting the changes in pressure.

What a musical note is

Now we can understand what a musical note is. If sound is nothing more than air vibrating, that oscillation can be faster or slower (higher or lower in pitch). Depending on how fast the oscillation is (cycles of compression and decompression per second), sounds can be classified, and that is where musical notes come from.

For example, the standard says that if the air vibrates 440 times per second (written 440 Hz), that sound is the note A. From that standard you can derive the rest of the 12 notes of the chromatic scale.

Because of the physical and mathematical laws that govern air vibrations (which we won’t go into here), notes are cyclical. If A is 440 Hz, any frequency obtained by multiplying or dividing it by 2 is the same note. So 110 Hz, 220 Hz, 440 Hz, 880 Hz and 1,760 Hz are all A, all consonant with one another, each one higher than the last.

With the idea of frequency in place, three more concepts are worth introducing:

  • Octave distance: the number of times you have to multiply or divide by two to go from one note to another version of the same note is the distance in octaves. To go from the 110 Hz A to the 880 Hz A you multiply by two three times, so those two A notes are three octaves apart.
  • Distance between notes: given the frequency of a note, you get the next one by multiplying by the twelfth root of two (~1.05946), or the previous one by dividing by the same number. Starting from the 440 Hz A, the next note, A#, is 440 Hz times 1.05946, or about 466 Hz. Repeating the process gives the frequency of every note, always from a reference point: here, A at 440 Hz, which is set by convention.
  • Hearing range: at best, people can hear frequencies from 20 Hz to 20 kHz (20,000 Hz), although the range narrows sharply with age.
Diagram of notes and their frequencies, with the octave and the twelfth root of two

With that, a chord is easy to explain: any combination of three or more different notes played at the same time. Not every instrument can play several notes at once, so not every instrument can play chords on its own. Those that can are called polyphonic (guitar, piano) and those that can’t, monophonic (trumpet, flute).

What a sound looks like over time

Now we are ready to “see” notes. To do that, we will look at what a microphone records, which is simply a way of digitizing the pressure waves that make up sound.

Let’s start with the note E at 330 Hz, played on a piano.

Waveform over time of the note E at 330 Hz on piano

The chart shows how pressure changes over time. As described above, it is an oscillation that repeats: compressing and decompressing, going up and down. The chart shows the sound from the very beginning, so you can see the silence (value 0 on the vertical axis) and then the piano string starting to vibrate and produce the wave (yes, in case you didn’t know, a piano has strings).

Although this is sound as a microphone measures it and as our eardrum interprets it, at first glance the chart doesn’t tell us much.

Even less so with a chord, such as an E seventh, made up of four notes (E, G#, B and D), played on a guitar.

Waveform over time of an E seventh chord on guitar

Now there are four oscillations at once, and they start at different moments, so it is much harder to pick out each note or even understand what is going on.

Time-domain and frequency-domain representations

How can this data become more visual, intuitive and informative? First, note that the charts above are time-domain representations. A time-domain representation shows how a quantity (pressure, in this case) changes over time. It is the most common and simplest way to think about things, but not always the most revealing, as this case shows.

Another representation is widely used in audio processing (and in other fields, such as image processing): the frequency-domain representation. The concept is hard to grasp at first, but once it clicks it becomes very useful for thinking through problems, such as interpreting the data we are working with.

A frequency representation no longer shows how the measured quantity changes over time, but how the whole signal is made up in terms of the frequencies present in it. In more technical terms: how the signal’s energy is distributed across frequencies.

Put another way, a time representation shows the measured quantity at a given moment; a frequency representation shows, for a given frequency, how strongly it is present in the recorded signal.

The mathematical tool that converts a time representation into a frequency representation (and back) is the Fourier transform, which is implemented in almost every programming language.

What a note looks like in the frequency domain

As mentioned, the best setting for this is an audio signal like the one we have been using. Here is the frequency representation of the same E note.

Spectrum of the note E with its peak at 330 Hz and its harmonics

This is a frequency representation. Let’s go through the chart, identify its elements and link them to the concepts above.

First, the “intensity” is zero at every frequency except for a few specific values, where it is quite high. The first peak is at 330 Hz, which is exactly the frequency of E.

That makes complete sense: an E is an oscillation at 330 Hz, so it is logical for that to be the most prominent frequency in the signal, if not the only one.

It isn’t quite that simple, though: why are there peaks at other values, and what do they mean?

The first thing to notice is that those peaks are not at random frequencies but at multiples of 330 Hz. They are called harmonics, and they always appear at multiples of the vibration’s frequency (the fundamental frequency), unless the vibration is what we call a “pure tone,” in which case there would be a single peak at the fundamental.

Explaining what a pure tone is and what harmonics really are goes beyond the scope of this article and into much murkier territory. The one thing I would like to leave you with is that harmonics are what cause the cyclical nature of notes mentioned at the beginning.

What a chord looks like in the frequency domain

With the concepts reasonably clear for a single note, we can now use this representation on a chord, which is where it shows its real value.

Spectrum of the E seventh chord with the peaks of its notes

Remember that this is the frequency representation of an E seventh chord, made up of E, G#, B and D. The chart shows the four notes as peaks at their frequencies, along with their harmonics at the multiples of each. (The different heights of each note’s peaks have to do with how loudly each one sounds and with the instrument’s timbre.)

So we went from a time representation of the chord, which told us next to nothing, to a frequency representation, where you can clearly see which frequencies make it up and therefore which notes it contains. At no point did we have to worry about the notes not starting at the same moment: one of the main strengths of the frequency representation is that it takes time out of the equation and focuses only on the signal’s composition, regardless of order. (That is also one of its drawbacks: you lose the notion of time, and with it, the order.)

As a corollary, although we went from the time representation to the frequency representation, you can also go the other way. That opens the door to many ways of modifying a sound: change it in the frequency domain, then bring it back to the time domain to get the original sound with new characteristics.

Applications: heart rate and sales or demand cycles

These frequency analysis concepts have many applications in other fields and industries. Here are two.

Detecting heart rate

A fairly direct application is detecting heart rate from an electrocardiogram. An ECG records the heart’s electrical activity over time, so it is clearly a time series. The heartbeats show up in that signal, and they are periodic. One of the first and most basic things you can do with this series is identify the frequency of the beats: you apply exactly what we did with sound waves, and that gives you the heart rate.

Electrocardiogram

Periodicity analysis

A very common case involves measurements over time (time series), such as a company’s sales, profit margin or demand, that contain repeating cycles. A beach supply store will sell more in summer and less in winter; a restaurant will probably be busier on weekends than on weekdays. Sometimes the length of these cycles is obvious (a year and a week, in these examples), but sometimes it isn’t, or you simply want to detect it automatically without relying on an industry specialist, as in electric load forecasting. That is where this approach helps: it detects how often the cycles repeat, the same way we detected the frequency of a sound to identify each note. Once again, moving a time series into the frequency domain lets you identify and measure features that would be very hard to see directly in the time domain.

Seasonal series across the seasons of the year

Frequency analysis beyond audio

In general, the frequency representation can be applied to any time series to surface information that would otherwise not be evident. It offers a different view of many problems and often leads to simple, robust and easy-to-interpret solutions. The only real limit is imagination: although here we always applied these concepts to time series, to things measured over time, they can be applied to any other kind of numerical data, such as the pixels of an image in image processing, among many other uses.

Iván Abatte
Data & Analytics Consultant

¿Listo para dar
el próximo paso?

Inicia tu camino
Otras publicaciones

Before asking how to use AI in a utility, it is worth asking whether the data is ready to support better decisions.

Six connected stages take a public power finance function from assessment to adoption, so AI can support better, faster and more traceable decisions.

Affordability, capital investment and resilience are now moving together. Utilities need scenarios to make decisions before the future becomes clear.

Quanam, a digital transformation, data and AI consultancy headquartered in Montevideo, Uruguay, is Certified in the Claude Partner Network. Its team holds Claude certifications, part of a path guided by one conviction: AI delivers more when people work alongside it.

Leave a Reply