As we did in our previous post, we are going to share with you a tutorial to learn about LTI Systems in the time domain and filtering. Therefore, we are going to see some exercises with Matlab code and solutions.
Before we start, make sure you know what the convolution is. Then, we are going to create the following sequence:
and plot it. To do that, simply write and run in Matlab the following code:
The function h[n] will be used in the activities as the system to process the different input signals. Its representation, in the discrete time domain is:
Figure 1. LTI System
Now that we have all the the tools we need to complete the tutorial, let’s get started!
Exercise 1: Linearity property of LTI system demonstration
In this activity we are going to study the linearity property of LTI systems. The first thing we are going to do is defining two signals, s1 and s2, that will be our inputs to the system:
Before running the previous code, notice that our input signals are sines that we are going to create using this function:
n=[start:1:L-1]; %this is the sampling interval%
sines= sin(omega*n + phase); %sinusoidal signal%
This is the representation of both signals:
Figure 2. Sine input signal
Figure 3. Second sine input signal
When we convolve each signal with h[n] separately and we add the outputs, we obtain the same output as if we first add s1 + s2 and then convolve with h[n]. The code to convolve each signal and add the outputs is:
Now, if we add s1+s2, we get:
Figure 4. System’s output
The code to get the previous signal and the system output is:
Now, we can plot both outputs, y3 and y4 in the same graph by using the following code:
And finally, as we see in the following image, both y3 and y4 are the same, therefore the system is linear:
Figure 5. Outputs comparison: linear property
Exercise 2: Time invariance property of LTI systems demonstration
In this example, we are going to see how if we process the input signal through the system and we delay the output, we will obtain the same result as if we process a shifted version of the input through it. This will happen in all the cases that our system is LTI; this is the invariance property.
Our input signal will be s1, created before. Now, in order to obtain a shifted version of it, we are going to use the function delay that we created in our previous tutorial. In order to shift the signal, for example, 10 samples, we write the following code:
Now, by doing:
y2=delay(y1,10,-100,200);%first output delayed
s2=delay(s1,10,-100,200);%second input as a delayed version of the first input
stem((-100:398),s2)%code needed to plot the second input
We will obtain the following outputs, y2 and y3:
Figure 6. Outputs comparison: time invariance property
which, as you can observe, they are identical.
Exercise 3: LTI systems and filtering
For this exercise we are going to create an additional h[n]. We will work with the following two systems:
h[n]=(u[n]-u[n-10]) cos(pn) e-0.9n
We will use them as filters. In order to define and plot them in Matlab, write the following code:
These are the two filters representation:
Figure 7. LTI filters
Now, how do we know if these filters are low, high or band pass if they are represented in the time domain? First, you can demonstrate that both filters are LTI systems by applying the properties explained above and the rest of them.
The input signal (the signal that we will filter through both filters) is going to be a periodic square signal that we going to create using the function that we used in our previous post:
This signal will look like the following one:
Figure 8. Periodic square pulses
In order to process it through h[n] and h1[n], we need to apply the convolution:
And we will obtain the following outputs, y1 and y2:
Figure 9. Filters’ outputs
As we can observe, the graphic at the right, which is the output from h[n], shows that this is a low-pass filter because the oscillations are slow. However, in the graphic at the right, corresponding to the system h1[n], the oscillations are faster, so this is a high-pass filter. You can observe this effect better if you represent the previous outputs, y1 and y2, by using the function plot:
Figure 10. Low pass filter output
Figure 11.High pass filter output
Exercise 4: Rough estimation of the frequency response
In this exercise, we are going to use our low pass filter, h[n], to process different sines signals through it in order to observe the change in amplitude and phase.
By representing the amplitude change of each sinusoidal, we would be representing an estimation of the frequency response of h[n].
Actually, we are using an interesting property of LTI systems for complex exponential inputs (sines and cosines, according to the Euler formula): when the input signal produces an output that is a constant (real or complex) multiplied by this input, this signal is an eigenvector of the system and its amplitude is an eigenvalue of the system.
Now, what about the phase change? The phase change is equivalent to the delay experimented by input when being processing by the system; actually, another way to represent the frequency response will be plotting the phase of the output signal against the selected frequencies.
For the first case, in order to plot the amplitude against the different frequencies, we use the following code:
Remember that this is a system’s frequency response estimation. Matlab provides functions that allow to study the frequency response in a more accurate way. For example, by using the function freqz, we simply write the following code:
Now, let’s compare ampH vs. omegas_vector and H vs omegas_vector:
Figure 12. Filter frequency response
As we can see, when using the function freqz (right graph), the shape is smoother than in our approximation but in both cases, we can observe that the cut frequency is around 1.5 and both systems represent the same: a Butterworth filter.
We hope this tutorial for you and don’t worry if you didn’t understand some process or steps: leave a comment below or send us an email to email@example.com and we will reply to you asap 🙂