The Discrete Fourier Transform: Amplitude scaling between the time and frequency domains
Contents
- Introduction
- (TLDR) Amplitude scaling in the time and frequency domains
- 2.1 Scaling concepts
- 2.2 DFT scaling computations: N is even
- 2.3 DFT scaling computations: N is odd
- 2.4 Amplitude scaling key result
- 2.5 Caveats
- 2.6 Example 1: Single frequency cosine wave
- 2.7 Example 2: Signal with three periodic frequency components (+ Matlab code)
- 2.8 Example 3: Cosine wave with linear ramping (i.e., a non-stationary signal)
- (In detail) Amplitude scaling in the time and frequency domains
- Amplitude scaling for periodic signals with a constant phase shift
- Power spectra
- Further reading
1 Introduction
Consider a real valued discrete time signal defined as
(1)
for amplitude , frequency (assumed to be an integer), total number of samples (also an integer), and integer time index .
Is there a single-sided frequency domain representation of where the signal magnitude, , can be read off at the appropriate bin frequency?
The short answer is provided below. More detail and proofs are provided later on.
2 (TLDR) Amplitude scaling in the time and frequency domains
2.1 Scaling concepts
The DFT of the signal given by equation 1, calculated in the conventional way as used in Matlab and Python, is defined as
(2)
resulting in a set of complex amplitudes (note that, as usual, expressing the DFT in terms of other frequency variables is also possible; we’ll stick with the representation in equation 2 as it’s notationally simplest).
Comments:
- We assume a rectangular window has been used to obtain the samples within , and so omit it from the definition.
- As we’ll see later on, implementing the DFT via equation 2 causes the complex amplitude entries to be scaled by a factor . However, since we know the scaling, the units of can be re-scaled so as to `match’ those of . We will called this re-scaled spectrum .
- Rescaling DFT amplitudes is useful where preserving the physical units of the time domain signal, e.g., sound pressure or surface velocity, will be of relevance in the frequency domain analysis.
- The spectrum structure of is slightly different depending on whether is even or odd. Therefore, the exact scaling calculations are listed separately in the next two sub-sections.
2.2 DFT scaling computations: N is even
If is even we calculate by taking a single-sided view of the spectrum , running from (i.e., up to the Nyquist limit), and scaling the complex amplitudes according to
(3)
where we note that the entries in at are purely real, and only appear once in the spectrum. A detailed account of this result is provided later on.
Evaluating the DFT for even is the more common case, due to use of FFT algorithms where signal blocks of length enable the greatest computational efficiency.
2.3 DFT scaling computations: N is odd
If is odd we calculate by taking a single-sided view of the spectrum , running from (i.e., up to the last available frequency bin below the Nyquist limit), and scaling the complex amplitudes according to
(4)
where we note that the entry in at is purely real, and only appears once in the spectrum. A detailed account of this result is provided later on.
2.4 Amplitude scaling key result
With reference to the cosine signal of equation 1, implementation of equation 3 or 4, as appropriate, will give us
(5)
as long as is an integer.
Therefore, for the scaled spectrum , the magnitude of the complex amplitude that appears in the frequency bin will be the same as the magnitude of .
In other words, the implied physical units of match those of .
Note: If the DFT is instead expressed in terms of cyclic frequency (Hz), this result may be written as
(6)
for entries other than at 0 Hz and Nyquist.
Or, in words, if we examine the frequency bin of corresponding to (where is the sample rate), and apply appropriate scaling, then the resulting scaled magnitude will equal ||.
2.5 Caveats
It is important to note that equation 5 is not, in general, exactly true. In particular, it does not compensate for spectral leakage effects that cause the signal energy within to be distributed across all complex amplitudes , if it is not exactly periodic in samples.
In fact, it is only strictly true under the following assumptions:
- Periodicity: The signal only contains frequency components that are exactly periodic across samples, e.g., for an input like that in equation 1, should be an integer (note that if contains multiple frequency components, each of them needs to be exactly periodic in samples for the neat result of equation 5 to hold for each component).
- Stationarity: The signal components within are stationary within the analysis window (i.e., they do not grow or diminish).
- Windowing: As noted earlier, a rectangular window has been used.
Despite these caveats, in appropriate settings, and when the number of samples is large relative to the sample rate, this amplitude scaling provides a version of the DFT that is quite useful in cases where retaining physical units in the frequency domain is important.
2.6 Example 1 – Single frequency cosine wave
This section provides an illustrative example where we know, in advance, the values of , , and which define the signal in equation 1. This ensures that is periodic in samples; furthermore, we assume there are no sources of noise in the signal. This is not realistic, but it’s helpful in illustrating the principle of DFT amplitude scaling.
Imagine that the signal has been obtained by sampling the velocity output of a laser doppler vibrometer. The units of are therefore metres/second (i.e., velocity). The value represents the peak velocity amplitude of the oscillation recorded in , and it’s not hard to imagine that this might be an important number to preserve when examining the vibrometer signal in the frequency domain.
Let’s choose some specific numbers, as follows:
(7)
where we see that is a pure cosine wave that is exactly periodic in samples.
Figure 1 shows a plot of in the time domain (upper), the regular double-sided frequency domain (centre), and the scaled single-sided frequency domain (lower, obtained via equation 3).
Observations from Figure 1:
- Upper: As expected, the time domain signal has 80 samples in total, an amplitude of 1, and it completes 6 full cycles within the window of samples.
- Centre: The regular DFT-computed frequency domain representation reveals a single non-zero complex amplitude, at bin index , of magnitude 40 (i.e., ). As expected, the frequency domain amplitude has accumulated a scaling factor that depends on . Only the lower half of the spectrum is shown (i.e., up to ), but we know from elsewhere that a conjugate copy of this lower half appears in the upper half of the spectrum, with another non-zero bin entry at , also of magnitude .
- Lower: The scaled DFT-computed frequency domain representation reveals a single non-zero complex amplitude, at bin index , of magnitude 1. In other words, this demonstrates that, under these idealised conditions, equation 5 is indeed satisfied. We therefore have an appropriate way to scale our DFT so its units match those of our time domain signal.
2.7 Example 2 – Signal with three periodic frequency components (+ Matlab code)
We can expand the previous example for a signal containing three frequency components that are periodic in samples. Code to illustrate this is shown below (note that the somewhat convoluted indexing in lines 6, 11, and 12 is to emphasise the difference between the usual DFT indexing of equation 2, which starts at 0, and what is required in Matlab, which starts at 1).
N = 80; % Total number of samples A1 = [1,3,8]; % Signal amplitude (time domain) k1 = [6;10;17]; % Signal frequency (time domain) nVec = 0:N-1; % Time index vector kVec_SS = nVec((0:(N/2))+1); % Single-sided frequency index vector x = A1*cos((2*pi*k1*nVec)./N);% Make a discrete time domain signal x_dft = fft(x); % Basic DFT of x x_dft_S = x_dft((0:(N/2))+1); % Single-sided DFT of x (even-length N) x_dft_S((1:(N/2)-1)+1) = (2/N)*x_dft_S((1:(N/2)-1)+1); % Scaled single-sided DFT of x x_dft_S(1) = (1/N)*x_dft_S(1); % Deal with DC x_dft_S(end) = (1/N)*x_dft_S(end); % Deal with Nyquist stem(kVec_SS, abs(x_dft_S)) xlabel('Frequency bin') ylabel('DFT magnitude (scaled)')
The result of the code above is shown in Figure 2.
2.8 Example 3 – Cosine wave with linear ramping (i.e., a non-stationary signal)
Three important caveats about the use of DFT scaling were outlined above. In this example, we briefly illustrate the relevance of the second caveat, i.e., stationarity.
(8)
which is the product of our original cosine wave (equation 1) and a linearly increasing ramp from 0:1.
The signal defined by equation 8 is interesting, because it seems to have only a single frequency component, but an evolving amplitude. Hence, it is not stationary, and there is no sense in which it has a single time domain amplitude. We would expect that scaling the complex amplitudes of its DFT in the frequency domain, via equation 3, will provide a similarly ambiguous result.
Analysis of this signal, following a similar structure to that of Example 1, is illustrated in Figure 3. We observe:
- Upper: The linear ramp has an average value of 0.5.
- Centre: The spectrum no longer has a single frequency component at , but instead all the bins have non-zero magnitudes. The signal energy in is therefore spread across all frequencies.
- Lower: The scaled DFT has , which is the same as the average value of the ramp. So in some sense the scaled DFT representation is still useful, in that it’s telling us something about the average value of the frequency component at , which does correspond with what we might expect from the time domain representation.However, because we know the `actual’ form of the time domain signal, via equation 8, we know that this does not correspond to a steady cosine wave. In real world measurements where we can’t be sure that the time domain signal is steady, care is needed in interpreting the scaled DFT.
- Key message: Care is needed in how we interpret scaled DFT amplitudes, particularly when our time domain signal varies in amplitude over the course of the analysis window, and/or is not strictly periodic within the analysis window.
3 (In detail) Amplitude scaling in the time and frequency domains
3.1 Introduction
Having demonstrated the basic calculations required to produce a scaled version of the DFT, such that amplitude units in the time and frequency domains match each other (with caveats), in this section we will lay out some of the mathematical proofs that underpin this useful result.
3.2 DFT of a cosine signal that is periodic in
Let’s start by evaluating the DFT of the pure cosine signal defined in equation 1, using equation 2 and Euler’s identity, to give
(9)
Notice that in cases where either or evaluate to 1, the corresponding summation becomes a sum of 1, times over, which gives us .
Notice also that in cases where and are not equal to 1 (see here for details), we can re-express equation 9 as a closed form finite geometric series, to give
(10)
Equations 9 and 10 are very useful results, which will become clear when we consider what happens for particular values of and .
3.2.1 The case where
Consider : Via equation 9, the exponent within becomes 0, and hence . By inspection we see that
(11)
Meanwhile, the exponent within is not 0 (nor is it an integer multiple of ), and hence . We therefore examine the corresponding expression for in equation 10, and see that the numerator evaluates to 0 (since for any integer ), and the denominator not to zero, and hence
(12)
Via a similar argument, all terms of , other than at , also evaluate to 0.
(13)
from which we notice that the amplitude term has been scaled by a factor .
As expected, is the `lower half’ of the cosine wave’s DFT representation. The factor of comes from the complex representation of a cosine wave as a pair of oppositely rotating complex phasors, and the factor from the DFT summation itself. Both of these will be `undone’ via appropriate re-scaling, summarised below.
3.2.2 The case where
Consider : Via equation 9, the exponent in the term is , and hence (for any value of ). By inspection we see that
(14)
Meanwhile, the exponent in the term is not 0 (nor is it an integer multiple of ), and hence . We therefore examine the corresponding expression for in equation 10, and see that the numerator evaluates to 0 (since for any integer ), and the denominator not to zero, and hence
(15)
Via a similar argument, all terms of , other than at , also evaluate to 0.
(16)
Similar comments can be made about the meaning of as those the preceding sub-section.
3.2.3 Special case where
Consider : If we go back to our original DFT of equation 2, a few steps of algebra reveal that
(17)
The entry at is often called as the `DC’ bin, and is formed by adding together all the samples in . It is also purely real, for a real-valued , and appears only once in the spectrum. %Unlike the entries for , there is no constant scaling factor by
For the signal of equation 1, which is perfectly periodic in samples, it is both intuitively clear, and quite straightforward to demonstrate, that if , the sum of all samples of will evaluate to 0.
In the specific case where , our signal becomes the unit step, scaled by . Therefore equation 17 becomes
(18)
By inspection we see that the average value of must be , and an appropriate scaling of the DFT to match this at is given by
(19)
3.2.4 Special case where
Consider : Again returning to our original DFT of equation 2, a few steps of algebra reveal that
(20)
since .
This is interesting since, as with , is always purely real. It is also unique, without a separate `lower half’ and `upper half’ representation across the analysis bandwidth.
If , we know via equations 12 and 15 that
(21)
However, if , via equation 9 we obtain
(22)
Therefore, as with the case, appropriate scaling of is achieved via
(23)
3.3 Summary
Pulling together all of the above, for a single frequency cosine signal of amplitude , integer frequency , and sampled over samples:
For : The DFT, , has amplitude at each of (`lower half’) and (`upper half’). If we want a single-sided spectrum representation (i.e., ) with spectral amplitudes that match (i.e., ), we therefore need to scale via
(24)
For : The DFT, , has a single complex amplitude of value . For these bins only, our scaled DFT is therefore obtained via
(25)
At last, these expressions provide the DFT scaling condition given at the start in equation 3, in cases where is even.
In cases where is odd, there is no bin entry at exactly , so we don’t need a special scaling there. The rest of the arguments can be translated quite straightforwardly from the case where is even.
4 Amplitude scaling for periodic signals with a constant phase shift
What happens to the results in the preceding section if we introduce a phase shift to the discrete time signal, and instead analyse this new signal defined as
(26)
Following the same analysis, but skipping most of the steps, it is possible to show, via a similar argument to that in equation 9, that
(27)
where and are defined exactly as in equation 9.
Equation 27 reveals a pair of complex-valued spectral amplitudes, which we know via the Hermitian symmetry property of the DFT to be the conjugates of each other. Following a similar analysis to that above, at we have
(28)
Via the multiplicative property of complex numbers (magnitude of a product is the product of the magnitudes), the magnitude is given by
(29)
since for any constant . Clearly, scaling this result requires the same computations as previously.
In other words, whatever the initial phase of the discrete time signal, the DFT amplitude scaling approach can be applied in the same way. However, in general it should be applied to the magnitude of the (complex valued) spectral amplitudes.
5 Power spectra
To be added.
6 Further reading
[1] Jens Ahrens et al (2020). Tutorial on Scaling of the Discrete Fourier Transform and the Implied Physical Units of the Spectra of Time-Discrete Signals. Audio Engineering Society Convention e-Brief 600, 2020.
[2] Mathworks: Amplitude Estimation and Zero Padding
[3] Mathworks: Webinar on Understanding Power Spectral Density and the Power Spectrum