Reading material: Chapter 5 of CSSB
In the last lecture we wrapped up the first part of CSSB[1] and from this lecture note onwards we are in the second part which is all about analysis of systems. We start by laying the groundwork with concepts of impulse response, frequency response and convolutions which help completely characterize single input, single output (SISO) linear time invariant (LTI) systems.
Recall that we loosely described linearity as the characteristic of a system that shows "proportionality in response". More formally a system that is linear satisfies the additivity and homogeneity properties.
The latter means that if the input is scaled by some factor then so is the output. That is, if is a system that takes a (possibly vector) input and outputs then for all scalars . The additivity property means that when provided an input that is the addition of two quantities, the system output can be described as the sum of the outputs to the individual quantities, i.e. . Together, these properties are said to endow linear systems with the superposition principle.
Thus, for linear systems and in particular linear time-invariant systems (LTI), to understand the system's response to very complicated inputs, it suffices to break apart the input into small manageable pieces, calculate its response to these pieces, and then sum it all up together and this is precisely what impulse functions let us do.
We are already familiar with the definition of the impulse function as the idealized signal which is only nonzero at time and takes on an amplitude such that
where we have used the fact that the impulse is only nonzero when to change to . Then we pull it out of the integral because it doesn't depend on the integration variable. At the final step we use the unit area property to calculate the integral as 1. Thus ,we see that the impulse function has the ability to pick out a single value amongst all the values could take.
Now, we are quite familiar with the notion of changing to the frequency domain via the Fourier transform as a change of basis to complex exponentials or equivalently to sinusoid. Then, let us take a step back and ask the following question.
As we remarked, by the principle of superposition, for linear systems it suffices to figure out what the system's response is to individual inputs. Since we can represent in the time domain as a continuously weighted sum/integral of the impulse function, it turns out that the response of LTI systems to the impulse function (called the impulse response) characterizes its response to any and all inputs.
Recall that for time invariant systems, time shifting the input is the same as time shifting the output , i.e.: . Therefore the above is a powerful statement that tells us we can find the response of an LTI system to arbitrarily complex inputs by simply weighting and summing (or integrating) its responses to a sequence of shifted impulses.
The operation performed in (1) is common enough in signal processing to warrant its own name: convolution. Some sources denote convolution with a but this is often confusing because of the wide use of to denote multiplication, especially on computers. Therefore we will use instead.
Using convolution we can represent the output of any LTI system to an input using its impulse response as:
where we have used the fact that convolution operation is commutative to get the second equality.
The astute reader may have noticed the similarity of (2) with that of the definition of the cross correlation of two functions. Indeed one can think of convolution of with as the cross-correlation of with or with . Thus the main difference is that in convolution, one of the signals is reversed in the time axis. For calculating the system response, CSSB explains this reversal as:
When implementing convolution, we reverse the input signal, because it is the input signal’s smallest time value that produces the initial output.
but you might as well accept it as a definition. To see visually the difference between convolution and cross-correlation, see below image from Wikipedia:
Let us find the convolution of and over the non-negative real line. By definition we have that
Rearranging we have,
The animation below shows the result of convolving two square pulses.
The impulse function is intimately related to Fourier transform because of the simple fact that the Fourier transform of the unit impulse function is unity. Indeed we have that,
This is an important property of the impulse function because it allows us to characterize the so called spectrum of the system. In other words, since the impulse function has a constant amplitude across all frequencies, the system response to the impulse response tells us exactly what it does to signals at each frequency.
By considering the above properties we can show the below Fourier transform pairs:
Time domain | Frequency domain |
---|---|
Now let us turn our attention to the question of what is the equivalent of the convolution operator in the frequency domain. After all, we started this course proclaiming that the time and frequency domain representations of signals are equivalent. Therefore, it is only practical that we examine what happens to the all important convolution operation used to define the time response of LTI systems via the impulse response in the frequency domain. Let us take the Fourier transform of the convolution of two functions:
where in the third line we changed the order of integration and in the following line we used the fact that the Fourier transform of a time shifted version of a function is its Fourier transform multiplied by an exponential determined by the shift. In other words, if is the Fourier transform of then is .
Thus we see that convolution in the time domain becomes multiplication in the Fourier domain. The reverse also holds true, namely convolution in the frequency domain becomes multiplication in the time domain. This observation accords us a strategy to avoid performing convolution and stick with multiplication, to find the system response, that is, if we are willing to tolerate an inverse Fourier transform. The strategy is as follows:
Take the Fourier transform of the impulse response and the input to the system to get and respectively.
Perform the multiplication in the frequency domain: .
Take the inverse Fourier transform .
Now that we have established the relationship between the time and frequency domains for the impulse function, now is a good time to review properties of the Fourier transform.
We state the following properties in the below table without proof.
Name | Time Domain | Frequency Domain |
---|---|---|
Linearity | ||
Time scaling | ||
Time delay | ||
Complex shift | ||
Time reversal | ||
Convolution | ||
Multiplication | ||
Differentiation | ||
Time multiplication |
By now we know that almost always, on a computer, functions and signals are all represented by a list of numbers. Therefore, the discrete version of the convolution is what gets really implemented:
Here is a visual example of what that looks like:
As usual, people far smarter than me have worked on making these somewhat mathematical topics accessible to everyone. In particular, Grant Sanderson has produced an excellent video on the topic of convolution, that I would highly recommend watching. Moreover, the interested student should definitely, check out a few other videos that he references (e.g. regarding the DFT algorithm).
Hopefully, having developed some more intuition about convolution, now let us turn to the issue of the impulse function in the digital domain.
Of course the impulse function is an idealization - in fact it is not even a real function in the mathematical sense, rather we have defined it via the properties it should have. But this leaves open the question of how to implement something so idealized on a digital machine. The approach we take is to ask: "What is a good enough approximation to the impulse function?
The answer, as is often in life, is it depends. In particular, it depends on the signal/system characteristics that we are analyzing. In the below figure we plot the magnitude spectrum for a few pulse signals on the left. The pulses are 1 ms, 2 ms and 5 ms long each and the DFT assumes a sampling frequency of 1 kHz. We see that only the true discrete impulse function (1 for the first sample and zero after) has the expected characteristic.
Now consider a system whose characteristic is akin to a low pass filter with a cutoff of 2 Hz. If we zoom-in on the -axis we see that even the 2 ms pulse can serve as an impulse function over this frequency range.
In MATLAB there are two functions that implement convolution. There are the conv
and filter
functions with the latter being a far more general function. For the former, the function signature is as follows:
y = conv(x, h, 'shape')
where x
and h
are the input signals and shape
is a parameter that specifies what the output should look like.
Parameter | Output length | Function |
---|---|---|
full | Zero pads as necessary | |
same | Zero pads but only returns central sum | |
valid | No zero padding |
Note that in either cases the output will require normalization by the length of samples.
Consider the following MATLAB code:
x=1:6
y=1:5
default = conv(x, y)
default_flip = conv(y, x)
valid = conv(x, y, 'valid')
valid_flip = conv(x, y, 'valid')
same = conv(x, y, 'same')
same_flip = conv(y, x, 'same')
and carefully observe the output:
default =
1 4 10 20 35 50 58 58 49 30
default_flip =
1 4 10 20 35 50 58 58 49 30
valid =
35 50
valid_flip =
35 50
same =
10 20 35 50 58 58
same_flip =
20 35 50 58 58
As you can see, only the full
(default) mode of convolution preserves its commutativity. The equivalent of conv(h, x)
using the filter
command in MATLAB is filter(h, 1, x)
.
We remarked that convolution in the time domain is equivalent to multiplication in the frequency domain. This below example, based on CSSB Example 5.7 shows that this is indeed the case. Clicking on the image will get you the code that generated it for the website, and in Chapter 5 you can find the Python code.
The equivalent MATLAB code from CSSB is shown below for completeness sake.
% Example 5.7 Given the system impulse response below, find the output of the system
% to a sawtooth wave (Figure 5.20)having a frequency of 400 Hz.
% Use both convolution and frequency domain approaches.
% Also find an plot on a dB-semilog scale the transfer function of the system.
% Since the sawtooth has a frequency of 3.2 Hz, we will use a sampling interval of 4 kHz
%
close all; clear all;
fs = 160; % Sample frequency
T = 1; % Time in sec;
t = (0:1/fs:T); % Time vector
N = length(t); % Determine length of time vector
x = sawtooth(20*t-pi/2,.5); % Construct input wave
h = 5* exp(-5*t).*sin(100*t);
subplot(1,2,1)
plot(t,x,'k');
title('A) Input Signal','FontSize',12);
xlabel('Time (sec)','FontSize',14); ylabel('x(t)','FontSize',14);
ylim([-1.2 1.2]);
subplot(1,2,2);
plot(t,h,'k');
title('B) Impulse Response','FontSize',12);
xlabel('Time (sec)','FontSize',14); ylabel('h(t)','FontSize',14);
% Calculate output using convolution.
y = conv(x,h); % Calculate output
figure;
subplot(2,1,1)
plot(t,y(1:N),'k'); hold on;
title('Time Domain (convolution)','FontSize',12);
xlabel('Time (sec)','FontSize',14); ylabel('y(t)','FontSize',14);
% Now calculate in the frequency domain.
TF = fft(h); % Take Fourier transform of iimpulse response
X = fft(x); % Take Fourier transform of input
Y = X.*TF; % Take product in the frequency domain
y1 = ifft(Y); % Take the inverse fourier transform to get y(t)
subplot(2,1,2)
plot(t,y1,'k');
title('Freqeuncy Domain (multiplication)','FontSize',12);
xlabel('Time (sec)','FontSize',14); ylabel('y(t)','FontSize',14);
Considering our discussion of digital or discrete convolution above, it is straightforward to note that whenever one of the sequences or is a constant, we end up performing some sort of weighted averaging. In particular, when the constants are or we get an or point moving average if the sequences and are also of length or respectively as shown in below figure (you are encouraged to write down the MATLAB version of the code).
N, t = 10, 0:0.01:2π # We are taking N=10 point average
f(t) = sin(t) + rand() # Generates a noisy sinusoid
plot(t, f.(t), label="Noisy sine") # Plots it
z(t) = conv(f.(t), repeat([1/N],N)) # Convolve with a constant vector
# Convolution result may be different length than time vector
# but result is still on [0, 2π]
plot!(LinRange(0, 2π, length(z(t))), z(t), label="Smoothened sine",
title="Taking 10 point average")
[1] | CSSB is divided into three parts, signals, systems and circuits. |