CMP4101 Signal Analysis in The Time Domain
CMP4101 Signal Analysis in The Time Domain
• A sinusoid is any signal that follows a basic sine wave pattern at a single
frequency
• It can be real-valued or complex (all real-world signals are real-valued).
• General:
Recall:
5
Intro to MATLAB for DSP
Example 2.1
Use MATLAB to construct a sinusoidal signal having an amplitude of 5.5 and a
frequency of 10 Hz. Construct the signal in a 1000-point array. Assume a
sampling frequency fs = 1000 Hz
Solution:
Step 1: Number of data points in the signal. Here, we are given N=1000 (If not
given, use this as some sort of default)’
Step 2: Construct a time vector of the same length as N. The discrete points in
time are determined by the sample interval, 𝑇𝑠 or the sample frequency fs :
𝑛
𝑡 = 𝑛 𝑇𝑠 =f (n is the position of the signal value in the sequence, and goes from
s
1 to N (same as 0 to N-1)
Step 3: (Code): Write the script
6
Intro to MATLAB for DSP
7
Signal Properties: Basic Measurements
• Most signals are complicated and defy a straightforward analytical
description.
• Basic measurements can be applied to extract more information
8
Mean of a Signal
• Discrete signal: Add signal values and divide by the length of the
1 𝑁
𝑥ҧ = σ 𝑥
𝑁 𝑛=1 𝑛
• Continuous signal: Integrate the signal over time and divide by the
time length
9
Root Mean Square Value
• Mean does not give information about variability of a signal
• Root-Mean-Square (RMS) value: Square, Take the Mean, then take
the square root of the mean.
1
1 𝑁
Discrete signal: 𝑥𝑟𝑚𝑠 = σ𝑛=1 𝑥𝑛2 2
𝑁
1
1 𝑇 2 𝑑𝑡 2
Continuous signal: 𝑥𝑟𝑚𝑠 = 𝑥(𝑡)
𝑁 0
Solution:
Refer to Example 2.1. Here, N is not given so we can arbitrarily choose N=1000.
We are also not given a sampling frequency. Following Nyquist’s theorem, the
sampling frequency should be at least twice the highest frequency in the signal
(this time, the constant frequency of 4 Hz). The higher the better. Let us then
arbitrarily choose fs = 1000 Hz.
12
Signal to Noise Ratio
– Most waveforms consist of signal + noise
– One of the goals of DSP is to separate the signal from noise
– The signal-to-noise-ratio or SNR quantifies the relative amount
of signal and noise.
𝑠𝑖𝑔𝑛𝑎𝑙
𝑆𝑁𝑅 = 20 log 𝑑𝐵 , both measured in rms amplitude
𝑛𝑜𝑖𝑠𝑒
o Positive SNR: Signal is greater than noise
o Negative SNR: Noise is greater than signal
13
SNR Example
Example 2.3
Consider a sinusoid signal contaminated with various amounts of white noise.
14
Variance and Standard Deviation
• Mean and rms apply to both deterministic and stochastic signals
• However, some properties only describe a signal’s random behavior. The
most common is the signal variance (randomness/fluctuation/variability), 𝜎 2
1
• For discrete signals, 𝜎 2 = 𝑁−1 σ𝑁
𝑛=1(𝑥𝑛 − 𝑥ҧ )
2
Quiz: The small difference between rms and 𝜎 when 𝑥ҧ = 0 lies in the division
by N vs N-1. Why do we divide by N-1 when calculating the variance?
15
Standard Deviation Example
Example 2.4
Generate a 5000-point array of Gaussian distributed i.e., normal numbers and
calculate the standard deviation of those numbers.
Solution
Use randn to generate the array, std to calculate the standard deviation
(Help in MATLAB always comes in hand e.g…
1
𝜎 2 = 𝑁 σ𝑁
𝑛=1(𝜎𝑛 )
2
𝜎
𝜎𝑛𝑜𝑖𝑠𝑒 =
𝑁
• Therefore, averaging multiple measurements from the same sources
reduces the standard deviation of the measurement’s noise, by the square
root of the number of measurements. It is thus common to make multiple
measurements wherever possible and average the results.
17
Ensemble Averaging
18
Time Domain Analysis: Correlation
• The basic measurements of mean, variance, standard deviation, and rms
capture the most important features of a signal.
This equation scales the correlation coefficient to be between ±1, but if we are not
concerned with the scale, then it is not necessary to normalize with the standard
deviations and N-1.
If the means are zero, then the correlation can simply be approximated by:
1
𝑟𝑥𝑦 = σ𝑁
𝑛=1 𝑥 𝑛 𝑦[𝑛]
(𝑁)
19
Example 2.5
Three pairs of signals and the normalized correlation between them. Note the high correlation between
The sine and triangle wave (center) and the zero correlation between the sine and cosine (top)
20
Time Domain Analysis: Covariance
1
cov= (𝑁−1) σ𝑁
𝑛=1(𝑥𝑛 − 𝑥)
ҧ (𝑦𝑛 − 𝑦)
ത
This equation is like that for computing the Pearson Correlation, except that it is
1
not normalized by 𝜎 𝜎
𝑥 𝑦
21
Orthogonal signals and orthogonality
• Orthogonal: perpendicular
• If two signals are orthogonal, then:
σ𝑁
𝑛=1 𝑥 𝑛 𝑦[𝑛]=0
22
Cross correlation
• Repeated shifting and correlation of a reference signal across the entire target
signal, to get the best match
• Used to determine similarity between a signal and a reference waveform when
the relative position for the best match is unknown.
• Works even when reference is shorter than target
𝑁
1
𝑟𝑥𝑦 𝑘 = 𝑦[𝑛]𝑥 𝑛 + 𝑘
𝑁
𝑛=1
Where k is the shift variable, which ranges over positive and negative integers, up
to some max value.
If two signals are the same length and one is shifted, there are no matching points.
The signal that is short is extended with zeros to extend computation beyond a
nominal point, a practice known as zero padding.
23
Example 2.6
24
Autocorrelation
𝑁
1
𝑟𝑥𝑥 𝑘 = 𝑥[𝑛]𝑥 𝑛 + 𝑘
𝑁
𝑛=1
Where k is the shift variable, which ranges over positive and negative integers, up
to some max value.
25
Example 2.7
26
Autocovariance and Cross covariance
Cross covariance
𝑁
1
𝐶𝑥𝑦 𝑘 = (𝑥 𝑛 − 𝑥 𝑛 )(𝑦 𝑛 + 𝑘 − 𝑦 𝑛 )
𝑁
𝑛=1
Autocovariance
𝑁
1
𝐶𝑥𝑥 𝑘 = (𝑥 𝑛 − 𝑥 𝑛 )(𝑥 𝑛 + 𝑘 − 𝑥 𝑛 )
𝑁
𝑛=1
27
Practice Questions
1. If a signal is measured as 2.8V and the noise is 30mV, what is the SNR in dB?
2. A single sinusoid signal is buried in noise. If the rms value of the noise is 0.6V and
the SNR is 20dB, what is the rms amplitude of the sinusoid?
3. Two 30Hz sine waves have a relative phase shift of 300 . What is the time
difference between them? If the frequency of these sine waves doubles, but the
time difference stays the same, what is the phase difference between them?
4. Replicate all the MATLAB examples in this lecture set.