# Unwanted frequencies in sawtooth tone

Since 440 represents an A note, a 55 Hz tone also represents an A, since it is at 1/8 the frequency. However, when I generate this note in Audacity, I always get unwanted frequencies appearing as small peaks below the fundamental and all the harmonics.

Here's an example of a 55 Hz sawtooth wave generated at a 48000 Hz sample rate:

You can clearly see those small peaks starting at 5 Hertz. What causes these unwanted frequencies to appear?

Edit: I finally realised that these "ghost" frequencies are actually the result of aliasing because the sawtooth wave is not being band-limited (id est: not having its maximum frequency limited). The harmonics beyond the Nyquist frequency are being "mirrored down" to frequencies whose Hertz are multiples of the greatest common divisor between the fundamental frequency and the sample rate. In this case, the GCD between 55 and 48000 is 5, which explains the aliases appearing at multiples of 5 Hz. Another example would be the fact that a 43.75 Hz sawtooth wave generated non-bandlimited at 48000 Hz would produce aliases at multiples of 6.25 Hz.

• Just to be clear, you do know that a sawtooth wave is not a pure tone, right? Only sine waves are pure tones, so any other function, even if it's periodic at 55Hz, will necessarily have harmonic peaks at multiples of 55 Hz. That said, the sub-harmonics do look like an artifact, but it's hard to diagnose further than Sean E. Lake's observation that they're likely to be due to the envelope without additional information about exactly what it is you're doing. Oct 5 '17 at 18:53
• Would Signal Processing, or possibly Electrical Engineering, be a better home for this question? Oct 5 '17 at 18:53
• Yes, precisely, that's what "sub-harmonics" refers to. But the question is unclear on what the role of the sawtooth wave is, as well as its harmonics. Why not re-run this with a sine wave, and cut out a source of noise and confusion? Oct 5 '17 at 19:55
• If your 'situation' is entirely within the digital domain, then why not state that? I've noticed a certain 'laziness' on your part when it comes to providing sufficient context. Is that by design? What is you intention? Oct 6 '17 at 3:05
• Actually, even if you think this is in the digital domain, @AlfredCentauri 's theory may have something to it. Because many such software packages produce some of their signals either from sampled instrument sounds or using linear predictive encoding of non digitally produced sounds or other means that can and does encode contamination into the digital model. Sibelius does this, for instance. How is the sawtooth produced? You need to describe the whole signal processing path that leads to what you have: you almost certainly have some kind of intermodulation happenning there. Piano synthesis .. Oct 8 '17 at 12:57

Your sampling rate is 48k at 55Hz, so each period is 872.73 samples. The size of your FFT is 65536. It fits 75.093 period of the signals. The algorithm takes 75 periods to plot the chart. This leaves 0.093 periods between consequitive FFT transforms. 0.093 periods at 55Hz correaponds to a frequency of 5.1Hz that matches the ghost frequency that you see within the margin of error.

This frequency or its harmonics are not present in the sound, but are a mathematical error created by the size of the FFT transform (2^16) not relating by a whole number to the number of samples in the period of the signal.

Furthermore, by the same logic, the 5.1Hz ghost creates a secondary artifact at 0.04Hz that you also see. Specifically, 5.1hz is 9,350.6 samples per period at 48k. The 65536 FFT size fits 7.0087 periods. 7 periods are displayed at about 5Hz and the 0.0087 period error at 5Hz creates a 0.04Hz ghost that you see on the left. At about -80dB, the values are small and are affected by the rounding and other errors, by the precision of the computer clock, and other factors, so the actual values that you see may slightly vary.

The calculation shows that the artifacts should diminish, if you reduce the generated frequency from 55Hz to approximately 54.93Hz. Alternatively you can increase the sampling frequency to 48.06k. However, you cannot change the FFT size just slightly, because it must be a power of 2.

• Changing to 54.93 only increases the "ghastliness" of the frequencies though. I think it is because each period is not an integer number of samples (and thus the rounding) that results in these ghost frequencies? Whenever the sample rate is an integer multiple of the frequency of the tone, there are no "ghosts." But whenever the sample rate is not an integer multiple of the frequency, these ghosts reappear. Oct 15 '17 at 1:13
• So I was pretty close. Essentially the same idea, only with the sample rate instead of the FFT size divisible by the frequency. I'm glad you have it figured :) Oct 15 '17 at 1:43
• So it all comes down to "ghost frequencies will appear whenever (frequency)/(sample rate) is not a whole number"? But that "triangle" at the lower left of the spectrogram appears all the time. Oct 15 '17 at 2:11
• @ElEctric I think we've established for sure that the ghost artifacts are created by the substandard signal processing in the software. A good FFT software would interpolate the signal first to a 32-bit floating point format, so all artifacts move down below the level of resolution. This one obviously just uses the samples without interpolation. There's nothing really you can do with a bad piece of software, but replace it with a better one. Fortunately there is no shortage of software tools today. You can get a different FFT program or just use a different workstation instead of Audacity. Oct 15 '17 at 2:55
• It's not substandard signal processing. What I have come to conclude is that if the length of each period is not an integer number of samples, ghost frequencies will appear at every integer multiple of the GCF of the tone frequency and the sample rate at large FFT sizes. The only exceptions are "square-like" waveforms (anything followed by itself inverted and then the whole thing repeated, such as a square or triangle wave), where the ghosts appear at only odd harmonics of the GCF, and a sine wave (pure tone), where there are no ghosts regardless of the divisibility. Oct 15 '17 at 5:24

I can't be certain that this is generating your peaks, but any tone that starts and stops won't be 100% pure; a pure tone has no beginning and no end. Consider a tone that starts at $0$ at $t=0$, vibrates for time $\tau$, and then turns off. As an equation, that looks like this: $$y(t) = \sin(2\pi f t)\, \Theta\left(\tau-t\right)\, \Theta(t),$$ where $\Theta(x)$ is the Heaviside (unit step) function. If we integrate that against $\mathrm{e}^{i\omega t} (2\pi)^{-1/2}$, we get: \begin{align} \tilde{y}(\omega) & \equiv \int_{-\infty}^\infty \sin(2\pi f t)\, \Theta\left(\tau-t\right)\, \Theta(t) \frac{\mathrm{e}^{i\omega t}}{\sqrt{2\pi}} \operatorname{d}t \\ &= \int_0^\tau \left(\frac{\mathrm{e}^{i2\pi f t}-\mathrm{e}^{-i2\pi f t}}{2i}\right)\frac{\mathrm{e}^{i\omega t}}{\sqrt{2\pi}} \operatorname{d}t \\ & = \frac{1}{2i\sqrt{2\pi}}\left[\frac{\mathrm{e}^{i2\pi f t + i\omega t}}{i(2\pi f+\omega)} - \frac{\mathrm{e}^{-i2\pi f t + i\omega t}}{i(-2\pi f+\omega)}\right]_{t=0}^\tau \\ & = -\frac{1}{2\sqrt{2\pi}} \left[\frac{\mathrm{e}^{i[2\pi f + \omega ]\tau}}{(2\pi f+\omega)} - \frac{\mathrm{e}^{i[-2\pi f + \omega ]\tau}}{(-2\pi f+\omega)} - \frac{1}{(2\pi f+\omega)} + \frac{1}{(-2\pi f+\omega)}\right] \end{align} If $f\tau=N$ is an integer, then we can simplify the above to: $$\tilde{y}(\omega) = \frac{\sqrt{2\pi}f}{\omega^2-(2\pi f)^2} \left(\mathrm{e}^{i\omega\tau} - 1\right).$$

Taking the absolute square to get something proportional to the power yields: $$P \propto \tilde{y}^* \tilde{y}= \frac{(2\pi f)^2}{\pi (\omega^2 - (2\pi f)^2)^2} (1 - \cos(\tau\omega)).$$

To see if this is the dominant contributor to your unwanted harmonics, try producing a tone that lasts twice as long, and one that lasts half as long, and see how that affects their locations. You should also expect unwanted harmonics from sampling and digitization, though I don't know how to describe where they'll pop up.

Edit: I didn't notice you were talking about a sawtooth wave. As @EmilioPisanty noted, saw tooths are not sine waves. The saw tooth is responsible for the dominant harmonics on the right side of the graph. Drop those (to get a pure sine wave), and you get something that is plausibly of a squared Lorentzian form. Also, the unwanted harmonics don't start around $5\operatorname{Hz}$, notice the edge of a purple lobe off the end of the graph. I'd bet the first lobe is near $0 \operatorname{Hz}$, exactly as you'd expect if you didn't have an integer number of wavelengths in your wave-form. $0\operatorname{Hz}$ represents a net constant offset to the signal, and that sort of unbalancing is what happens when you don't spend an equal time above and below equilibrium.

Edit: Sparked by @WetSavannaAnimalakaRodVance's comment, I decided to code up my own tone generator. The sawtooth wave I generated using Golang, writing out to text, and importing to Audancity produces the same spectrum. Just like the Audacity generated spectrum, the $5\operatorname{Hz}$ peak vanishes when the "Size" parameter is reduced to 16384, or lower. What's going on here, I think, is there is additional windowing imposed by how the spectrum is generated:

Plot Spectrum take the audio in blocks of 'Size' samples, does the FFT, and averages all the blocks together.

The windowing from generating the spectrum seems primarily to affect a sort of noise floor, though, so this just disguises the peak. I don't know the details of what's going on, but there's a hint in comparing the square wave with "square wave, no aliasing". Judging by the zoomed in version, where ringing is apparent, the "no aliasing" wave is generated using a sum of sine waves, as opposed to the simple mathematical algorithm with sharp cutoffs.

Point being, this is probably a case of aliasing: square and sawtooth waves contain frequency information that is higher than the sampling rate can faithfully represent, producing the audio equivalent of a Moire pattern (i.e. a low frequency tone/beat frequency).

• OP's sampling rate at 48 kHz looks to me like it's much too high for sampling artifacts to show up at that range, and this is the same digital computer feeding signal to itself, so there can't be any ADC artifacts. But, that said, maybe there's noise from the finite precision coming in, as an 'effective' ADC effect? If so, OP can probably diagnose that by using a higher bitrate. Oct 5 '17 at 18:59
• Note that the peaks are all occurring at multiples of 5. Might it have to be due to the fact that 48000 is not divisible by 55? Oct 5 '17 at 19:31
• @ElEctric How long was the sample used to generate the graph? Oct 5 '17 at 19:44
• @ElEctric You realize that the tones you're worried about are more than $55\operatorname{dB}$ from the peak, right? That's more than 300,000 times quieter than the peak. What I mean by "beat frequency" is a difference between the frequencies inherent in these processes. See what happens when you set the sampling rate to $352,800\operatorname{Hz}$, for example. Were I you, I'd export the sound file then FFT it in Octave or Matlab to get a more accurate picture. Oct 6 '17 at 1:54
• Are you absolutely sure of that (i.e. do you ken Audacity specifically)? Because many such software packages produce some of their signals either from sampled instrument sounds or using linear predictive encoding of non digitally produced sounds or other means that can and does encode contamination into the digital model. Sibelius does this, for instance. If you look at the vertical axis, these artefacts are very feint indeed. Oct 8 '17 at 8:32

the sawtooth waveform is rich in harmonic content and this would show up in the spectrum. note also that computer-generated waveforms are sometimes spectrally impure because of algorithmic errors and D-to-A conversion artifacts.

• Note that OP is not complaining about the harmonic content (at 110 Hz, 165 Hz, etc), but instead about the sub-harmonic content that is not part of the expected sawtooth-wave signal. Similarly, this appears to be the audacity software feeding a digital signal directly to its own analyzer, so neither DAC nor ADC artifacts are directly applicable. Oct 6 '17 at 9:37