In one of my Github repositories I included 3 signals:
- Dirac Delta
- Linear Sine Sweep
- Logarithmic Sine Sweep
I explained the Dirac Delta and why we use it in my article: What Is An Impulse Response? However, I have not explained why I bothered including the sine sweeps. In this article, I want to talk about sine sweeps as a testing method. This article will not be all encompassing but it should give you a sufficient understanding of the subject. I will explain why they are used, how they are different and why you would use over other methods. I have two reasons for writing this article:
- They are important testing signals.
- I got flustered in a job interview and got this (embarrassingly) wrong.
This article carries very few citations that discuss these things directly. However, I have included useful links below that will be helpful to those in audio.
What is a Sine Sweep?
Some of you may be aware that a sine wave is a pure tone. This means that a sine wave with a frequency of 100 Hz is made up of only one frequency (100 Hz). It is not a signal comprised of frequencies between 99-101 Hz or 99.9999- 100.0001 Hz. It is a pure tone. If you do not understand this concept, please take a moment to look at this previous article.
Therefore, a sine sweep is a sine wave that increases (or decreases) in a smooth manner over the duration of the signal. There are two classes of sine sweeps: Linear Sine Sweepsand Logarithmic Sine Sweeps. Sometimes these are also known as chirps.
Sine sweeps are useful when measuring room acoustics, speaker systems, analog equipment or really any system that is not Linear or Time Invariant. Unlike white noise, a Maximum Length Sequences (MLS) or a sine sweep is less prone to error due to time invariance. However, a sine sweep can be pushed to a higher signal level than a MLS which yields a higher signal-to-noise-ratio.
Therefore, sine sweeps are preferable for many measurement applications where we need to derive an impulse response to be used in the creation of a transfer function. This class of signals can be used to investigate THD, inter-modulation distortions, phase distortion and many other aspects of a system.
Linear Sine Sweep vs Logarithmic Sine Sweep
A linear sine sweep increases or decreases frequency at a constant linear rate over time. A logarithmic sine sweep does so at an exponential rate (sometimes it is called exponential sine sweep as a result). That may not have seemed like a useful description but there are major implications as a result.
Time Domain Analysis
The plot below shows the beginning of the sweeps in comparison for the first 10,000 samples. Both plots are of the sine sweep files. Both files are a sweep from 20 Hz to 20 kHz in 1 second at a constant magnitude. All code for these images can be found in my Python Sketchpad on Github.
Please understand that we are not looking at 1 second of time in the plots above. Note that the linear sine sweep immediately goes from the lower frequency of 20 Hz to the very high frequencies within the first 10,000 samples. There is not even a full 20 Hz cycle in there. The log sweep makes a much more gradual change and as a result, the audio file has the time to actually resolve the whole wavelength of the lower frequencies (practically).
I think this can also be displayed (in a more tangible manner) using a spectragram. A spectragram gives us the frequency response over time. The intensity of the color refers to the magnitude of the signal.
As you can see, the logarithmic sine sweep spends more time in the lower frequencies than the higher frequencies. The linear sweep spends equal time at each frequency. Let’s change the y-axis to prove a point to differentiate these signals. All code for these images can be found in my Python Sketchpad on Github.
By examining the plot above, you may notice that the y-axis (frequency) is now logarithmic. This is to better represent human hearing and serves to demonstrate the true nature of these signals. To think of it another way, a linear sweep spends equal time at each frequency but the higher frequencies make up more of the audible spectrum. A logarithmic sweep spends equal time within each octave, which means that the lower frequencies occupy more time.
If you have read any of my previous articles, you will know that there is a relationship between the time domain and frequency domain representation of a signal. Therefore, we should take a moment to examine the magnitude-frequency response of these signals. All code for these images can be found in my Python Sketchpad on Github.
Please note that the x-scale (frequency) is logarithmic and the y-scale (magnitude) is in dB to better represent human hearing. There are two behaviors to note with these magnitude-frequency responses. The first is the rippling at the ends of the frequency ranges. The second is the general trend of each line.
As you may notice, the linear sine sweep exhibits a relatively uniform distribution of all frequencies within the swept range. This is because it spends equal time at each frequency. However, it is not exactly uniform. Due to the fact that it spends less time at the lower frequencies (and not even enough time for a full wavelength to resolve), there is less signal energy in that region and there is a drop in the magnitude frequency response as a result. Let us call this depression in the magnitude-frequency response the cutoff frequency. We could extend the cutoff frequency of the linear sine sweep if we made a significantly longer measurement. Instead of a 1 second sweep, we could make a sweep of 4 minutes and probably get very close to 20 Hz. Obviously this is not feasible.
That same fact also exists for the logarithmic sweep. A logarithmic sweep spends more time at the lower frequencies and spends equal time within each octave. This is why there is a predictable, steady/constant rate of roll-off over the measured frequency range.
Why use a Logarithmic Sine Sweep?
You may be wondering, “Why would I bother using the logarithmic sine sweep if the linear sweep is more uniform in the magnitude-frequency response?” And the answer is:
If we use some standard signal processing techniques, we can get an impulse response with greater precision at lower cost.
Let me show you how.
Logarithmic Sine Sweeps, Convolution, The Inverse Filter and the Impulse Response
As we can see from the previous section, the logarithmic sweep has less energy in the higher frequencies and the Fourier Transform reflects that. How can we possibly mitigate that?
The answer is to create an inverse filter with a corresponding impulse response. Our inverse filter can be created in a number of ways but the result is the same. The impulse response of our inverse filter is an exponentially decaying sine sweep that transitions logarithmically from 20 kHz to 20 Hz. Let’s compare these two signals and their time domain representations below.
It may not be immediately obvious but, by taking Fourier Transform we can see that these two waves have inverse properties. The inverse logarithmic sweep spends more time in the higher frequencies and, as a result, it exhibits a higher magnitude in those frequencies as shown in the magnitude-frequency response below.
We can use this inverse logarithmic sweep to filter the logarithmic sweep by a process known as a discrete convolution. Discrete convolution has been discussed in a previous article I have written about IIR and FIR filters. Indeed, we can use this same method to derive an impulse response. The following plots show the result of the convolution process.
As you can see, we now have derived an impulse response very similar to a Kronecker Delta function. This signal has a corresponding (mostly) uniform magnitude-frequency response.
By passing a logarithmic sine sweep through a system (such as a reverb) one will get an effected output. This effected output can then be convolved with the inverse logarithmic sine sweep. This will yield the impulse response of the system. By taking the Fourier Transform of the impulse response, we will have a corresponding magnitude-frequency response. We can then use this information to create a transfer function, a filter or analyze the system further.
I hope this article was informative and will serve you well when looking to understand DSP and its many applications. I personally wrote this post so that I would never get that question wrong in an interview ever again. In future articles, it is highly likely we will have to go through the measurement procedure and application of what I have outlined here. Until then:
Be good to each other and take it easy…
Will Fehlhaber is an Acoustics Engineer and Audio Programmer from the UK and Bay Area.
- Digital Filter Design: The Analog Prototypes for IIR Filters
- Understanding the Z-Transform Part IV: Analyzing an IIR Filter
- Understanding the Z-Transform III: Analyzing an FIR Filter
- Digital Filter Design: Create an FIR Filter via Windowing
- Understanding the Z-Transform II: Understanding z and the Z-Plot