Unit 1: Introducing Digital Signal Processing#
Colophon#
An annotatable copy of the notes for this presentation is available as Worksheet 1.
The Jupytext source code for this page is introduction/index.md.
You can view the notes for this presentation as a webpage (HTML).
This page is downloadable as a PDF file.
Signals and Systems for Dummies#
Signals and Systems for Dummies (SS4D) [Wickert, 2013] provides a useful introduction to the topics that will be covered in this module and it is in the Reading List as a recommended text. I have based this presentation on Chapter 1 which is available as a downloadable PDF from the publishers.
You should read Chapter 1 of SS4D in conjunction with the notes for this presentation.
Note that Signals and Systems for Dummies is available as an e-book from the University Library.
Topics#
Continuous-time signals#
Continuous signals are represented mathematically by functions which vary continuously with time.
Sinusoidal signals (e.g. AC) are pretty fundamental in electrical engineering. The mathematical model of a sinusoidal signal is:
Exercise#
First attempt#
For this expression, we wish to match each of the symbols to its definition.
Without computing anything, see if you can complete this table.
Symbol |
Definition |
---|---|
\(A\) |
Phase in radians |
\(f_0\) |
Frequency in Hz |
\(\phi\) |
Amplitude |
\(2\pi f_0\) |
Frequency in rad/s |
Gaining insight using computers#
To help us answer these questions, let’s use our Mathematical tools to plot a signal like this and explore it. The example we will use is from Signals and Systems for Dummies (SS4D: page 12):
Wolfram Alpha#
Here’s the link: https://www.wolframalpha.com
Paste this into the search box
plot 3 cos(2 pi 2 t - 3 pi/4)
Try changing the numbers to gain insight.
MATLAB#
In MATLAB we would need to tackle this by breaking down the steps.
%Make sure that we have a clean workspace
clear all
format compact
Define t
t = linspace(0, 1, 100);
Define x
x = 3 * cos(2*pi*2*t - 3*pi/4);
Plot result and label plot
plot(t,x)
title('A Sinusoidal Signal')
xlabel('Time t (s)')
ylabel('Amplitude')
grid
If you want to execute this in MATLAB, you can create a file by copying this text into an m-file
:
%%file sinewave.m
% SINEWAVE - plot function $x(t) = 3 \cos(2\pi t - 3 \pi/4)$ for $t = 0\ldots 1$
%% Set up the problem
% define t
t = linspace(0, 1, 100);
% define x
x = 3 * cos(2*pi*2*t - 3*pi/4);
%% Plot result and label plot
plot(t,x)
title('A Sinusoidal Signal')
xlabel('Time t (s)')
ylabel('Amplitude')
grid
Created file '/Users/eechris/code/src/github.com/cpjobling/eg-247-textbook/introduction/sinewave.m'.
edit sinewave
To run this script, just type the filename without the .m extension.
sinewave
(Download sinewave.m)
To run this script, just type the filename without the .m
extension. Try adjusting the values of the numerical constants and see what insights you gain.
Returning to the Question#
Sinusoidal signals (e.g. AC) are pretty fundamental in electrical engineering. The mathematical model of a sinusoidal signal is:
Exercise – second go after gaining insight from your computer#
Using the insight just gained by exploring this function with a computer, match each of the symbols to its definition again.
Symbol |
Definition |
---|---|
\(A\) |
Phase in radians |
\(f_0\) |
Frequency in Hz |
\(\phi\) |
Amplitude |
\(2\pi f_0\) |
Frequency in rad/s |
Did you get different answers?
Supplementary question#
What is the period of the waveform in seconds?
Notes
In communications and electronic signal processing, the frequency of sinusoidal signals us usually given in cycles per second or Hz.
In mathematics, the frequency is always expressed in radians per second.
In some courses, including later in this one and in EG-243 Control Systems, the frequency \(2\pi f_0\) is often called the natural frequency and is usually written \(\omega_n\).
Try This Yourself#
Use any or all of computing tools that you have access to to explore other sinusoids. Change the values of the variables and explain what happens.
Try adding sinusoids of different amplitudes and different frequencies together and see what happens.
Change
cos
tosin
and see what happens.
Continuous-time Systems#
Systems operate on signals. In mathematical terms, a system is a function or an operator, \(H\{\}\) that maps the input signal \(x(t)\) to an output signal \(y(t)\).
Mathematically we would write this:
Example 1#
An example of a continuous-time system is an electronic amplifier with a gain of 5 and level shift of 2: \(y(t) = H\{x(t)\} = 5x(t) + 2\).
In this course, we will model such systems as block diagram models in Simulink.
Block diagram model in Simulink#
The Similink code can be downloaded from this file gain_level_shift.slx.
Discrete-time Signals#
Discrete-time signals are a function of a time index \(n\). A discrete-time signal \(x[n]\), unlike a continuous-time signal \(x(t)\), is only defined at integer values of the independent variable \(n\). This means that the signal is only active at specific periods of time. Discrete-time signals can be stored in computer memory.
Example 2#
Consider the following simple signal, a pulse sequence:
We can plot this in MATLAB as a stem plot
Procedure#
Define function using this text:
%%file y.m
% Define the function
function [ y ] = x( n )
if n < 0 | n >= 10
y = 0;
else
y = 5;
end
end
Created file '/Users/eechris/code/src/github.com/cpjobling/eg-247-textbook/introduction/y.m'.
edit y
(Open y.m).
%% Define sample points
n = -15:18;
%% Make space for the signal
xn = zeros(size(n));
%% Define sample points
n = -15:18;
%% Make space for the signal
xn = zeros(size(n));
%% Compute the signal x[n]
for i = 1:length(xn)
xn(i) = y(n(i));
end
%% Plot the result
stem(n,xn)
axis([-15, 18, 0, 6])
title('Stem Plot for a Discrete Signal')
xlabel('Sample n')
ylabel('Signal x[n]')
grid
Discrete-time Systems#
A discrete-time system, like its continuous-time counterpart, is a function, \(H\{\}\), that maps the input \(x[n]\) to the output \(y[n] = H\{x[n]\}\). An example of a discrete-time system is the two-tap filter:
The term tap denotes that output at time instant \(n\) is formed from two time instants of the input, \(n\) and \(n – 1\). Check out a block diagram of a two-tap filter system:
This system is available as a Simulink model discrete_system.slx
In words, this system scales the present input by 3/4 and adds it to the past value of the input scaled by 1/4. The notion of the past input comes about because \(x[n - 1]\) is lagging one sample value behind \(x[n]\). The term filter describes the output as an averaging of the present input and the previous input. Averaging is a form of filtering.
Signal Classifications#
Periodic#
Signals that repeat over and over are said to be periodic. In mathematical terms, a signal is periodic if:
Continuous signal \(x(t + T) = x(t)\)
Discrete signal \(x[n + N] = x[n]\)
The smallest \(T\) or \(N\) for which the equality holds is the signal period.
The sinusoidal signal we saw earlier is periodic because of the \(\mod 2\pi\) property of cosines. The signal of the sinusoid has a period 0.5 seconds (s), which turns out to be the reciprocal of the frequency \(1/f_0\) Hz.
Square Wave#
This code generates a square wave.
%% A Periodic signal (square wave)
t = linspace(0, 1, 500);
x = square(2 * pi * 5 * t);
This Square wave is a 5 Hz waveform sampled at 500 Hz for 1 second
plot(t, x);
ylim([-2, 2]);
grid()
title('A Periodic Signal')
xlabel('Time t (s)')
ylabel('Amplitude')
What is the period \(T\) in milliseconds?
Aperiodic#
Signals that are deterministic (completely determined functions of time) but not periodic are known as aperiodic. Point of view matters. If a signal occurs infrequently, you may view it as aperiodic.
This is how we generate an aperiodic rectangular pulse of duration \(\tau\) in Matlab:
%% An aperiodic function
tau = 1;
x = linspace(-1,5,1000);
y = rectangularPulse(0,tau,x);
plot(x,y)
ylim([-0.2,1.2])
grid
title('An Aperiodic Signal')
xlabel('Time t (s)')
ylabel('Amplitude')
Random#
A signal is random if one or more signal attributes takes on unpredictable values in a probability sense.
Engineers working with communication receivers are concerned with random signals, especially noise.
%% Plot a Random Signal
plot(0.5 + 0.25 * rand(100,1))
ylim([0,1])
grid
title('Random Signal')
xlabel('Time t (s)')
ylabel('Amplitude')
Domains for Signals and Systems#
Most of the signals we encounter on a daily basis reside in the time domain. They’re functions of independent variable \(t\) or \(n\). But sometimes when you’re working with continuous-time signals, you may need to transform away from the time domain (\(t\)) to another domain.
Other Domains you will encounter#
The most commonly used domains used when analyzing continuous-time signals are the frequency domain (\(f\) or \(\omega\)) and the Laplace \(s\)-domain (\(s\)).
Similarly, for discrete-time signals, you may need to transform from the discrete-time domain (\(n\)) to the frequency domain (\(\hat{\omega}\)) or the z-domain (\(z\)).
This section briefly introduces the world of signals and systems in the frequency, s-, and z-domains. More on these domains will follow.
Systems, continuous and discrete, can also be transformed to the frequency and s- and z-domains, respectively. Signals can, in fact, be passed through systems in these alternative domains. When a signal is passed through a system in the frequency domain, for example, the frequency domain output signal can later be returned to the time domain and appear just as if the time-domain version of the system operated on the signal in the time domain.
Consider the sum of a two-sinusoids signal
This can be coded as
%%file two_sines.m
%... plot two sinusoids signal
A1 = 2; f1 = 1;
A2 = 1.5;f2 = 2.2;
t = linspace(0, 3*(1/f1), 1000);
s1 = A1*cos(2*pi*f1*t);
s2 = A2*cos(2*pi*f2*t);
subplot(4,1,1)
plot(t,s1),ylim([-5,5]),xlabel('Time t (s) '),ylabel('s1')
subplot(4,1,2)
plot(t,s2),ylim([-5,5]),xlabel('Time t (s) '),ylabel('s2')
subplot(4,1,3)
plot(t,s1+s2),ylim([-5,5]),xlabel('Time t (s) '),ylabel('x(t) = s2 + s2')
subplot(4,1,4)
axis([0,4,0,2.5])
arrow([f1,0],[f1,A1]),text(f1,A1+0.2,'A1'),text(f1+0.05,0.2,'f1')
arrow([f2,0],[f2,A2]),text(f2,A2+0.2,'A2'),text(f2+0.05,0.2,'f2')
ylabel('Frequency Spectrum X(f)'),xlabel('Frequency (Hz)')
Created file '/Users/eechris/code/src/github.com/cpjobling/eg-247-textbook/introduction/two_sines.m'.
edit two_sines
Run
two_sines
(Download two_sines.m)
Viewing Signals in the Frequency Domain#
The top waveform plot, denoted \(s_1\), is a single sinusoid at frequency \(f_1\) and peak amplitude \(A_1\). The waveform repeats every period \(T_1 = 1/f_1\). The second waveform plot, denoted \(s_2\), is a single sinusoid at frequency \(f_2 > f_1\) and peak amplitude \(A_2 < A_1\). The sum signal, \(s_1 + s_2\), in the time domain is a squiggly line (third waveform plot), but the amplitudes and frequencies (periods) of the sinusoids aren’t as clear here as they are in the first two plots. The frequency spectrum (bottom plot) reveals that \(x(t)\) is composed of just two sinusoids, with both the frequencies and amplitudes discernible.
Think about tuning in a radio station. Stations are located at different center frequencies. The stations don’t interfere with one another because they’re separated from each other in the frequency domain. In the frequency spectrum plot, imagine that \(f_1\) and \(f_2\) are the signals from two radio stations, viewed in the frequency domain. You can design a receiving system to filter \(s_1\) from \(s_1 + s_2\). The filter is designed to pass \(s_1\) and block \(s_2\).
Fourier Transform#
We use the Fourier transform to move away from the time domain and into the frequency domain. To get back to the time domain, use the inverse Fourier transform. We will find out more about these transforms in this module.
Laplace and Z-Transform Domains#
From the time domain to the frequency domain, only one independent variable, \(t \to f\), exists. When a signal is transformed to the s-domain, it becomes a function of a complex variable \(s=\sigma + j\omega\). The two variables (real and imaginary parts) describe a location in the s-plane.
In addition to visualization properties, the s-domain reduces differential equation solving to algebraic manipulation. For discrete-time signals, the z-transform accomplishes the same thing, except differential equations are replaced by difference equations.
Systems Thinking and Systems Design#
See section Testing Product Concepts with Behavioral Level Modeling from Chapter 1 of SS4D ([Wickert, 2013] pages 18–20) and add some notes to summarize this for yourself.
We will use behavioural modelling
We will rely on abstraction
We work top-down
We make use of mathematics and mathematical software.
Familiar Signals and Systems#
See pages 21-23 of the free sample (Chapter 1) of [Wickert, 2013] for notes and details.