# LTI Systems Tutorial

|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:

h[n]= (u[n]-u[n-10])e-0.9n

and plot it. To do that, simply write and run in Matlab the following code:

h=exp(-0.9*(0:9)); stem((0:9),h);

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:

s1=sines(-100,200,pi/50,0); s2=sines(-100,200,pi/100,0); stem((-100:199),s1); stem((-100:199),s2);

Before running the previous code, notice that our input signals are sines that we are going to create using this function:

function sines=sine(start,L,omega,phase) n=[start:1:L-1]; %this is the sampling interval% sines= sin(omega*n + phase); %sinusoidal signal% plot(n,sines)%signal representation%

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:

y1=conv(s1,h); y2=conv(s2,h); y3=y1+y2; stem((-100:208),y3)

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:

s3=s1+s2; stem((-100:199),s3); y4=conv(s3,h);

Now, we can plot both outputs, y3 and y4 in the same graph by using the following code:

figure(1) subplot(1,2,1) stem((-100:208),y3); subplot(1,2,2) stem((-100:208),y4);

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:

s2=delay(s1,10,-100,200);

Now, by doing:

y1=conv(s1,h);%first output 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 y3=conv(s2,h);%second output figure(1) subplot(1,2,1) stem((-100:407),y2); subplot(1,2,2) stem((-100:407),y3); clear

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])e-0.9n

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:

h1=exp(-0.9*(0:9)); n=[0:9]; h2=cos(pi*n).*exp(-0.9*(0:9)); figure(1) subplot(1,2,1) stem((0:9),h1); subplot(1,2,2) stem((0:9),h2);

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:

t=[-200:1:200]; y=[ones(1,10),zeros(1,10)]; Nr=10; periodic=per(y, Nr); plot(periodic)

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:

y1=conv(h1,periodic); figure(2) subplot(1,2,1) stem((0:208),y1); y2=conv(h2,periodic); figure(2) subplot(1,2,2) stem((0:208),y2);

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:

h=exp(-0.9*(0:9)); n=[0:100]; omegas_vector=[0:pi/100:pi]; for i=1:length(omegas_vector); omega=omegas_vector(i); x=sin(omega*n); y=conv(h,x); ampH(i)=max(y); angleH(i)=angle(y(1)); end

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:

h=exp(-0.9*(0:9)); [H,W]=freqz(h);

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 contact@behindthesciences.com and we will reply to you asap ðŸ™‚