From differential to difference equations
2.1 Computer in the loop
2.1.4 Discrete frequency
If we sample the continuous signal,
x(t) = A cos(ωt) with a sample time of T ,
x(nT ) = A cos(ωnT ) = A cos(Ωn) where thedigital frequency, Ω, is defined as
Ωdef= ωT = 2πf T = 2πf fs
then the range of analogue frequencies is 0 < f < ∞ while the range of digital frequencies is limited by the Nyquist sampling limit, fs/2 giving the allowable range for the digital frequency as
0≤ Ω ≤ π
MATLABunfortunately decided on a slightly different standard in the SIGNALPROCESSING tool-box. Instead of a range from zero to π, MATLABuses a range from zero to 2 where 1 corresponds to half the sampling frequency or the Nyquist frequency. See [42].
In summary:
symbol units
sample time T or ∆t s
sampling frequency fs=T1 Hz angular velocity ω = 2πf rad/s digital frequency Ω = ωT = 2πff
s –
where the allowable ranges are:
0≤ω < ∞, continuous 0≤Ω ≤ π, sampled
and Nyquist frequency, fN, and the dimensionless Nyquist frequency, ΩN are:
fN =fs
2 = 1 2T [Hz]
ΩN =2πfN
fs
= π
It is practically impossible to avoid aliasing problems when sampling, using only digital filters.
Almost all measured signals are corrupted by noise, and this noise has usually some high or even infinite frequency components. Thus the noise is not band limited. With this noise, no matter how fast we sample, we will always have some reflection of a higher frequency component that appears as an impostor or alias frequency.
If aliasing is still a problem, and you cannot sample at a higher rate, then you can insert a low pass analogue filter between the measurement and the analogue to digital converter (sampler).
The analogue filter or in this case known as an anti-aliasing filter, will band-limit the signal, but not corrupt it with any aliasing. Expensive high fidelity audio equipment will still use analogue filters in this capacity. Analogue and digital filters are discussed in more detail in chapter5.
Detecting aliases
Consider the trend y(t) in Fig.2.3where we wish to estimate the important frequency compo-nents of the signal. It is evident that y(t) is comprised of one or two dominating harmonics.
Figure 2.3: Part of a noisy time series with unknown frequency components. The con-tinuous underlying signal (solid) is
sam-pled at T = 0.7, (•), and at T = 1.05 s (△). 0 1 2 3 4 5 6 7
−2
−1 0 1 2 3
time (s)
output
continuous Ts=0.7 Ts=1.05
The spectral density when sampling at T = 0.7s (• in Fig.2.3) given in the upper trend of Fig.2.4 exhibits three distinct peaks. These peaks are the principle frequency components of the signal and are obtained by plotting the absolute value of the Fourier transform of the time signal2,
|DFT {y(t)}|. Reading off the peak positions, and for the moment overlooking any potential
100
102 T
s = 0.7 s
fN=0.71
power
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
100
102 Ts = 1.05 s
fN=0.48
frequency (Hz)
power
Figure 2.4: The frequency component of a signal sampled at Ts = 0.7s (upper) and Ts = 1.05s (lower). The Nyquist frequencies for both cases are shown as vertical dashed lines. See also Fig.2.5.
problems with undersampling, we would expect y(t) to be something like y(t)≈ sin(2π0.1t) + sin(2π0.5t) + sin(2π0.63t)
However in order to construct Fig. 2.4we had to sample the original time series y(t) possibly introducing spurious frequency content. The Nyquist frequency fN = 1/(2Ts) is 0.7143 and is
2More about the spectral analysis or the power spectral density of signals comes in chapter5.
shown as a vertical dashed line in Fig.2.4(top). The power spectrum is reflected in this line, but is not shown in Fig.2.4.
If we were to re-sample the process at a different frequency and re-plot the power density plot then the frequencies that were aliased will move in this second plot. The△ points in Fig.2.3are sampled at ∆t = 1.05s with corresponding spectral power plot in Fig.2.4. The important data from Fig.2.4is repeated below.
Curve Ts(s) fN (Hz) peak 1 peak 2 peak 3
top 0.7 0.7143 0.1 0.50 0.63
bottom 1.05 0.4762 0.1 0.152 0.452
First we note that the low frequency peak (f1 = 0.1Hz) has not shifted from curve a (top) to curve b (bottom), so we would be reasonably confident that f1= 0.1Hz and is not corrupted by the sampling process.
However, the other two peaks have shifted, and this shift must be due to the sampling process.
Let us hypothesize that f2 = 0.5Hz. If this is the case, then it will appear as an alias in curve b since the Nyquist frequency for curve b (fN(b) = 0.48) is less than the proposed f2 = 0.5, but it will appear in the correct position on curve a. The apparent frequency ˆf2(b) on curve b will be
fˆ2(b) = 2fN(b)− f2= 2× 0.4762 − 0.5 = 0.4524
which corresponds to the third peak on curve b. This would seem to indicate that our hypothesis is correct for f2. Fig.2.5shows this reflection.
100
102 Ts = 0.7 s
fN=0.71
power
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
100
102 Ts = 1.05 s
fN=0.48
frequency (Hz)
power
Figure 2.5: Reflecting the frequency re-sponse in the Nyquist frequency from Fig.2.4shows why one of the peaks is ev-ident in the frequency spectrum at Ts = 1.05, but what about the other peak?
Now we turn our attention to the final peak. f3(a) = 0.63 and f2(b) = 0.152. Let us again try the fact that f3(a) is the true frequency = 0.63Hz. If this were the case the apparent frequency on curve b would be ˆf3(b) = 2fN(b)− f2 = 0.3224Hz. There is no peak on curve b at this frequency so our guess is probably wrong. Let us suppose that the peak at f3(a) is the first harmonic. In that case the true frequency will be f3 = 2fN(a)− ˆf3(a) = 0.8Hz. Now we check using curve b. If the true third frequency is 0.8Hz, then the apparent frequency on curve b will be ˆf3(b) = 2fN(b)− f3= 0.153Hz. We have a peak here which indicates that our guess is a good one. In summary, a reasonable guess for the unknown underlying function is
y(t)≈ sin(2π0.1t) + sin(2π0.5t) + sin(2π0.8t)
although we can never be totally sure of the validity of this model. At best we could either re-sample at a much higher frequency, say fs> 10Hz, or introduce an analogue low pass filter to cut out, or at least substantially reduce, any high frequencies that may be reflected.