Signals and Systems Lab Manual
Signals and Systems Lab Manual
Charitable Trust
Campus Address: Rukmini Knowledge Park, Kattigenahalli, Yelahanka, Bengaluru - 560 064
REVA University School of ECE
BTEC15F4200 L T P C
Signals and Systems Lab
Duration:14 Wks 0 0 2 2
Prerequisites:
Course Objectives:
Course Outcomes:
Contents
MATLAB Introduction
What is MATLAB?
MATLAB is the name of a software product developed by a company called
It is very general, powerful and popular. By skill demand, it is one of the top 10 computer
languages. There is no field untouched and uninfluenced by it and is used by millions of
people from all walks of life – students, teachers, researchers etc - worldwide.
Just a pick of the several applications: MATLAB has been used in projects such as
modelling energy consumption to build smart power grids, developing control algorithms for
hypersonic vehicles, analyzing weather data to visualize the track and intensity of hurricanes,
and running millions of simulations to pinpoint optimal dosing.
Why?
BECAUSE MATLAB
• first and foremost, is easy to use. Just like how you write on paper. No variable
declarations, No dimension declarations, No type declarations, No inclusion of libraries and
so on. It is all about mathematical computations -everything from simple to most complex.
• data visualization– i.e. simple to powerful graphics like 3D and animated graphics.
• much much more - for example, symbolic math, importing and exporting of data,
programming, publishing and interfacing to hardware.
• The strength of MATLAB is its matrix-based operations. Ability to deal with several
numbers at the same time rather than one at a time.
• MATLAB handholds from conceptualization to hardware implementation and
acceptance.
• simply put, MATLAB is all about everything you need to do a job from concept to
using.
• superb documentation, embedded help, free source code, demos, videos, user fora and
shared knowledge, MATLAB based subject books....
Disclaimer and scope:
In this introduction to MATLAB, we will only be scratching the surface. Just the flavour of
matlab for understanding its usage in signals and systems lab experiments. Also nothing can
beat built-in MATLAB documentation. But we will give enough push/guidance so that the
reader can be on his own with the various help mechanisms available in MATLAB.
Versions
MATLAB has two releases every year; they are called like 2015a, 2015b, 2016a, and 2016b.
Next one is expected in Feb-Mar 2017timeframe.
Invoking MATLAB and using MATLAB as a calculator
MATLAB is easier-to-use than a calculator and yet incomparably powerful.
Let us get started! INVOKE MATLAB! By double-clicking on the MATLAB icon on your
desktop.
Let us see some examples of using MATLAB for numerical calculations – MATLAB as a
calculator.
You can erase an entire line of command, without executing by pressing the [esc] key.
You can use Up-arrow or Down-arrow keys to access previously executed commands and
execute them after making changes using the LeftArrow, RightArrow to reach the place of
correction. Any previously executed command can be reexecuted as it is – using the same
method – if no correction is needed.
ORDER OF PRECEDENCE:
MATLAB follows normal mathematical rule of operator precedence BODMAS.
() highest precedence
Mathematical constants (not comprehensive list)
pi (MATLAB is case-sensitive, so pi, Pi, pI, PI are all different, for example!)
i,j (square root of -1, as long as you did not change the value of it by assigning some other
value to it.)
>>3+5i
ans =
3.0000 + 5.0000i
All the built-in constants can be reassigned. And other variables can be created with these
values.
How to get out of a logjam?
Ctrl+C
>>a=1;while a==1,end
Ctrl+C
>>
How to get out?
Key in exit or close the MATLAB window.
1. MATLAB BASICS
In these examples, the results are stored in ‘ans’. So the latest result overwrites the previous
‘ans’.
Sl.
Arithmetic operations MATLAB Expressions
No.
01 2.7183 + 3.1416 2.7183 + 3.1416
02 1947-1857 1947-1857
03 60x60 60*60
04 25 2^5
05 25 2^5 / (2^5-1)
25 − 1
06
3*(sqrt(5)-1) / (sqrt(5)+1)^2-1
Sl.
Trigonometric functions MATLAB Expressions
No.
01 sin (π/6) sin(pi/6)
02 cos (π) cos(pi)
03 tan (π/2 tan(pi/2)
04 Sin2 π/6 + cos2 π/6 (sin(pi/6))^2 + (cos(pi/6))^2
Example:
Given a=3; b=2;c=5; d=3;
a) y = a*b+c*d
= 3*2+5*3 => 6+15 => 21 => y = 21
b) y = a*(b+c)*d
= 3*(2+5)*3 => 3*7*3 => y = 63
c) y = (a*b)+(c*d)
= (3*2)+(5*3) => 6+15 => y = 21
d) y = a^b^d;
= 3^2^3 => 9^3 => y = 729
e) y = a^(b^d)
= 3^(2^3) => 3^8 => y = 6561
Initializing with
builtin functions MATLAB
Comments
in MATLAB / Expression
OCTAVE
1. A =
Creates 2X2 with 0’s
zeros(2);
2. B =
Creates 2X3 with 0’s
zeros(2,3);
3. C =
Creates 2X3 with 1’s
ones(2,3);
Array operations:
1. .* => Element by element multiplication
2. ./ => Element by element left division
3. .\ => Element by element right division
4. .^ => Element by element exponentiation
MATRIX PROBLEMS:
1. Assume
Simple x, y Plots
output:
%MATLAB Code to plot both sine and cosine in one figure window
clc;
t=0:0.00001:0.01;
A=10;
f=200;
y1=A*sin(2*pi*f*t);
y2=A*cos(2*pi*f*t);
plot(t,y1,t,y2);
xlabel('time axis');
ylabel('Amplitude');
title('sine/cosine wave plot');
%MATLAB Code to plot both sine and cosine in separate figure window
clc;
t=0:0.00001:0.01;
A=10;
f=200;
y1=A*sin(2*pi*f*t);
y2=A*cos(2*pi*f*t);
figure(1);
plot(t,y1);
xlabel('time axis');
ylabel('Amplitude');
title('sine wave plot');
figure(2);
plot(t,y2);
xlabel('time axis');
ylabel('Amplitude');
title('cosine wave plot');
%MATLAB Code to plot both sine and cosine by dividing the figure window:
clc;
t=0:0.00001:0.01;
A=10;
f=200;
y1=A*sin(2*pi*f*t);
y2=A*cos(2*pi*f*t);
subplot(2,1,1);
% Divides the figure window into 2 rows, 1 column and 1st position respectively
plot(t,y1); % plots the waveform in continuous form
xlabel('time axis');
ylabel('Amplitude');
title('sine wave plot');
subplot(2,1,2);
% Divides the figure window into 2 rows, 1 column and 2nd position respectively
plot(t,y2);
xlabel('time axis');
ylabel('Amplitude');
title('cosine wave plot');
clc;
clear all;
close all;
disp('Unit Impulse Signal Generation'); % disp is used to display messages on the
command window
N = input('Enter no of samples:'); % input is used to read the values through console
n = -N : 1 : N;
x = inline('1*(n==0)');
stem(n,x(n));
xlabel('Sample');
ylabel('Amplitude');
title('Unit Impulse Signal');
Output:
Unit Impulse Signal Generation
Enter no of samples: 10
% OUTPUT ARGUMENTS
% a the output sequence name
% b position vector for output sequence plotting
% INPUT ARGUMENTS
% c delay of the impulse sequence
% d start position for plotting c
% e end position for plotting e
clc;
clear all;
close all;
Output:
Enter delay of the impulse sequence c: 3
Enter start position for plotting d: -10
Enter end position for plotting e: 10
Output:
Unit Step Signal Generation
Enter no of samples: 10
% OUTPUT ARGUMENTS
% a the output sequence name
% b position index for output sequence plotting
% INPUT ARGUMENTS
% c delay of the impulse sequence
% d start position for plotting
% e end position for plotting
clc;
clear all;
close all;
c= input(' Enter delay of the impulse sequence c: ');
d= input ('Enter start position for plotting d: ');
e= input (' Enter end position for plotting e: ');
if c<d,
error('impulse sample will not be seen within the range of positions given')
end
n= d:e;
x = inline('1*(n>=c)');
stem(n, x(c,n));
xlabel('sample position');
ylabel('sample value');
title('plot of the desired sequence');
Output:
Enter delay of the step sequence c: 3
Enter start position for plotting d: -10
Enter end position for plotting e: 10
clc;
clear all;
close all;
disp('Unit Ramp Signal Generation');
N = input('Enter no of samples: ');
n = -N : N;
r= inline ('n.*(n>=0)');
stem (n, r(n));
xlabel('Sample');
ylabel('Amplitude');
title('Unit Ramp Signal');
Output:
Unit Ramp Signal Generation
Enter no of samples: 10
Max Amplitude: 10
Output:
Enter delay of the ramp sequence: 3
Enter start position for plotting d: -10
Enter end position for plotting e: 10
% x1 first sequence
% n1 first sequence start position
% x2 second sequence
% n2 second sequence start position
% y restulting sequence
% n resulting sequence positin vector
clc;
clear all;
close all;
x1= input('Enter the first sequence: ');
n1= input('Enter the first sequence start position: ');
x2= input('Enter the second sequence: ');
n2= input('Enter the second sequence position: ');
MIN = min(n1,n2);
MAX = max (n1+length(x1)-1,n2+length(x2)-1);
n=MIN:MAX;
y1=zeros(1,length(n));
y2=y1;
a=n1(1)-MIN+1;
b=n2(1)-MIN+1;
y1(a:a+length(x1)-1)=x1;
y2(b:b+length(x2)-1)=x2;
y = y1+y2;% sequence addition, y1-y2 for sequence subtraction
disp(y);
subplot(3,1,1)
stem(n,y1)
title(' Signal x1' );
subplot(3,1,2)
stem(n,y2)
title(' Signal x2');
subplot(3,1,3)
stem(n,y)
title(' Signal y, addition of x1 and x2')
Output:
clc;
clear all;
close all;
x1= input('Enter the first sequence: ');
n1= input('Enter the first sequence start position: ');
x2= input('Enter the second sequence: ');
n2= input('Enter the second sequence position: ');
subplot(3,1,1)
stem(n,y1)
title(' Signal x1' );
subplot(3,1,2)
stem(n,y2)
title(' Signal x2');
subplot(3,1,3)
stem(n,y)
title(' Signal y, multiplication of x1 and x2')
Output:
clc;
clear all;
close all;
Output:
Signal x(n)
5
-5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
Delayed signal x(n-n1)
5
-5
0 0.5 1 1.5 2 2.5 3 3.5 4
Advanced signal x(n+n2)
5
-5
-5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1
clc;
clear all;
close all;
n=-1:2;
x=[3 -1 0 -4];
subplot(2,1,1)
stem(n,x);
axis([-3 3 -5 5]);
title('Signal x(n)');
c=fliplr(x);
y=fliplr(-n);
subplot(2,1,2);
stem(y,c);
axis([-3 3 -5 5]);
title('Reflected Signal x(-n)');
Output:
clc;
clear all;
close all;
x=[3 -1 1 -4];
power=sum(abs(x).^2)/length(x);
disp(power);
Energy=sum(abs(x).^2);
disp(Energy);
Output:
6.7500
27
Theory:
The output y[n] of a LTI (linear time invariant) system can be obtained by convolving
the input x[n] with the system’s impulse response h[n].
The convolution sum is
Algorithm:
1. Input the two sequences as x1, x2
2. Convolve both to get output y.
3. Plot the sequences.
Matlab Implementation:
Matlab recognizes index 1 to positive maximum. Index 0 is also not recognized. The timing
information for a sequence is provided by another vector, say n=-3:5; creates a vector with
values from -3 to 5 with an increment of 1.
During plotting, the time vector size and the sequence size should be the same, i.e., the
number of elements in the sequence x1 and in its time vector n1 should be the same.
Similarly for x2 and y.
Matlab Program:
% CAUSAL SEQUENCES
%main part of computation
clc;
clear all;
close all;
x=input('Enter first sequence: ');
h=input('Enter second sequence: ');
y=conv(x,h);
disp('linear con of x & h is y= ');
disp(y);
subplot(3,1,2); % Divides the fig window into 3-rows, 1-Column & 2nd position
stem(h); % To display ‘h’ input in figure window
xlabel('time index n');
ylabel('amplitude ');
title('plot of h(n)');
subplot (3,1,3); % Divides the fig window into 3-rows, 1-Column & 3rd position
stem(y); % To display ‘y’ output in figure window
xlabel('time index n');
ylabel('amplitude ');
title('convolution output');
Calculations:-
h(n)= Impulse response of a system due to impulse input function.
y(n)= x(n) * h(n)
Using convolution property of the two delayed unit impulse sequence we get,
x(n)*h(n) = δ(n)+2δ(n-1) +3δ(n-2) + 4δ(n-3)
+2δ(n-1) + 4δ(n-2) + 6δ(n-3) + 8δ(n-4)
+3δ(n-2) + 6δ(n-3) + 9δ(n-4) +12δ(n-5)
x(n)*h(n) = δ(n) + 4δ(n-1) +10δ(n-2) +16δ(n-3) +17δ(n-4) +12δ(n-5)
Output :
Matlab Program:
% Two sided sequences (Non- Causal Sequences)
% Main part of computation
ny=[ybegin:yend];
y=conv(x,h);
disp('linear con of x & h is y=');
disp(y); % Displays the value of ‘y’ on Terminal window
subplot(3,1,2); % Divides the fig window into 3-rows, 1-Column & 2nd position
stem(n2,h);
xlabel('time index n');
ylabel('amplitude ');
title('plot of h(n)');
subplot (3,1,3); % Divides the fig window into 3-rows , 1-Column & 3rd position
stem(ny,y);
xlabel('time index n');
ylabel('amplitude ');
title('convolution output');
Calculations:-
x = [3 11 7 0 -1 4 2] h = [2 3 0 -5 2 1]
↑ ↑
x*h = [ 3δ(n+3)+11δ(n+2)+7δ(n+1)-1δ(n-1)+4δ(n-2)+2δ(n-3)]*[ 2 δ(n+1)+3 δ(n)-5 δ(n-2)+2δ(n-3)+δ(n- 4)]
CHALLENGE EXPERIMENT:
3. Write a general matlab program for linear convolution for any two general sequences
(causal and non-causal).
Given the difference equation or H(z), the impulse response of the LTI system is
found using filter or impz matlab/gnu-octave functions. If the difference equation
contains past samples of output, i.e., y[n-1], y[n-2], etc , then its impulse response is
of infinite duration (IIR). For such systems the impulse response is computed for a
large value of n, say n=100 (to approximate n=∞).
Given only the input sequence x[n] and the output sequence y[n], we can find the
impulse function h[n] by using the inverse operation deconv. (The conv operation
convolves 2 sequences x[n] and h[n] to obtain the output y[n]. If both y[n] and x[n]
are finite then the impulse response is finite (FIR).
The de-convolution operation is valid only if the LTI system is ‘invertible’.
Matlab Implementation:
FILTER One-dimensional digital filter.
Y = FILTER(B,A,X) filters the data in vector X with the filter described by vectors A
and B to create the filtered data Y. The filter is a "Direct Form II Transposed"
implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
If a(1) is not equal to 1, FILTER normalizes the filter coefficients by a(1).
% matlab program to find Impulse Response given the difference equation with zero initial
condition:
clc;
N=5;
b= [1 0.5]; % numerator coefficients
a=[1 -0.63 0.72]; % denominator coefficients
x=[1,zeros(1,N-1)]; % x=[1 0 0 0 0];
y=filter (b,a,x);
stem(y);
title('impluse response of the system without initial conditions');
Calculations:-
y[n]-0.63y[n-1]+0.72y[n-2] = x[n]+0.5x[n-1]
y[n] = 0.63y[n-1]-0.72y[n-2]+ x[n]+0.5x[n-1]
n=0; y[0] = 0.63y[0-1]-0.72y[0-2]+x[0]+0.5x[0-1]
y[0] = 1
= (0.63)(1)+(0.5)(1)
y[1] = 1.13
= (0.63)(1.13)-(0.72)(1)
y[2] = -0.008100
= (0.63)(-0.008100)-(0.72)(1.13)
y[3] = -0.818703
n=4; y[4] = 0.63y[4-1]-0.72y[4-2]+x[4]+0.5x[4-1]
= (0.63)(-0. 8187)-(0.72)(-0.0081)
y[4] = -0.509949
Result:
the impluse response of the system without initial conditions
1.0000 1.1300 -0.0081 -0.8187 -0.5100
% matlab program to find Impulse Response given the difference equation with initial
condition:
clc;
N=5;
b= [1 0.5]; % numerator coefficients
a=[1 -0.63 0.72]; % denominator coefficients
x=[1,zeros(1,N-1)]; % x=[1 0 0 0 0];
zi=filtic(b,a,[1 2]); % with initial conditions y(-1) = 1 and y(-2) = 2
y=filter (b,a,x,zi);
disp('the impluse response of the system with initial conditions');
disp(y);
stem(y);
title('impluse response of the system with initial conditions');
Calculations:-
y[n]-0.63y[n-1]+0.72y[n-2] = x[n]+0.5x[n-1]
y[n] = 0.63y[n-1]-0.72y[n-2]+ x[n]+0.5x[n-1]
Result:
the impluse response of the system with initial conditions
0.1900 -0.1003 -0.2000 -0.0538 0.1101
CHALLENGE EXPERIMENT:
1. Write a matlab program to extend the calculation of output for other standard inputs
like unit step, ramp and sinusoid (can use matlab inbuilt functions).
clear all;
close all;
tfinal=0.05;
t=0:0.00005:tfinal;
xt=cos(2*pi*f1*t)+cos(2*pi*f2*t);
fm=max(f1,f2);
fs=1.3*fm;
Ts=1/fs;
n=0:Ts:tfinal;
xn=cos(2*pi*f1*n)+cos(2*pi*f2*n);
figure(1)
subplot(3,1,1);
plot(t,xt)
xlabel('t')
ylabel('x(t)')
subplot(3,1,2);
stem(n,xn)
xlabel('n')
ylabel('x(n)')
subplot(3,1,3);
plot(t,xt,'b',n,xn,'r*-');
xlabel('t')
fs=2*fm;
Ts=1/fs;
n=0:Ts:tfinal;
xn=cos(2*pi*f1*n)+cos(2*pi*f2*n);
figure(2)
subplot(3,1,1);
plot(t,xt)
xlabel('t')
ylabel('x(t)')
subplot(3,1,2);
stem(n,xn)
xlabel('n')
ylabel('x(n)')
subplot(3,1,3);
plot(t,xt,'b',n,xn,'r*-');
xlabel('t')
fs=5*fm;
Ts=1/fs;
n=0:Ts:tfinal;
xn=cos(2*pi*f1*n)+cos(2*pi*f2*n);
figure(3)
subplot(3,1,1);
plot(t,xt)
xlabel('t')
ylabel('x(t)')
subplot(3,1,2);
stem(n,xn)
xlabel('n')
ylabel('x(n)')
subplot(3,1,3);
plot(t,xt,'b',n,xn,'r*-');
xlabel('t')
Output:
TMS320C6713 DSK
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C6713 DSK provides:
A USB Interface
SDRAM and ROM
An analog interface circuit for Data conversion (AIC)
An I/O port
Embedded JTAG emulation support
Connectors on the C6713 DSK provide DSP external memory interface (EMIF) and
peripheral signals that enable its functionality to be expanded with custom or third party
daughter boards.
The DSK provides a C6713 hardware reference design that can assist you in the development
of your own C6713-based products. In addition to providing a reference for interfacing the
DSP to various types of memories and peripherals, the design also addresses power, clock,
JTAG, and parallel peripheral interfaces.
The C6713 DSK includes a stereo codec. This analog interface circuit (AIC) has the
following characteristics:
The DSK includes 4 LEDs and 4 DIP switches as a simple way to provide the user with
interactive feedback. Both are accessed by reading and writing to the CPLD registers.
An included 5V external power supply is used to power the board. On-board voltage
regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A
voltage supervisor monitors the internally generated voltage, and will hold the board in reset
until the supplies are within operating specifications and the reset button is released. If
desired, JP1 and JP2 can be used as power test points for the core and I/O power supplies.
Code Composer communicates with the DSK through an embedded JTAG emulator with a
USB host interface. The DSK can also be used with an external emulator through the
external JTAG connector.
2. You will get workspace Launcher window in workspace select the drive other than
‘C’ and create a new folder by your SRN and click OK.
3. Click on project and select New CCS Project in that select the desired properties as
given in the picture and click on Finish button.
NOTE:
For real time programs select hello.cmd file and for non-real programs select C6713.cmd
4. Once you click on finish button you will get a CCS editor window, in that type the C
program and at the end click on SAVE button.
5. To rename the file name instead of main.c Right click on main.c which is in project
explorer window and select Rename icon or press F2 button.
6. You will get a new Rename Resource window there you give a new file name with
extension ‘.C’ and click ‘OK’.
7. Now to build the project click on HAMMER symbol which is on the top left
of editor window.
Note:
If any error occurs in the program that will be displayed in the console window which is at
the bottom of editor window. Clear that error again click on save button and repeat the same
above step.
8. After building the project to debug the program click on BUG symbol which is
on the top left of editor window.
9. Now to RUN the program click on Resume or F8 button which is on the top left
of editor window.
10. In the console window you can observe the output values.
For the very first time after installation of CCS software the following properties has to be
modified.
#include <stdio.h>
#include<math.h>
for(i=0;i<127;i++)
{
m[i]=sin(2*3.14*FREQ*i/24000);
printf("%f\n",m[i]);
}
}
NOTE:
Procedure is given in page number 48 to run code composer studio v6.1.3. Follow the steps.
main()
{
int m=3; /*Length of i/p samples sequence*/
int n=4; /*Length of impulse response Co-efficient */
int i=0,j;
int x[15]={1,2,3,4,0,0,0,0,0,0}; /*Input Signal Samples*/
int h[15]={1,2,3,0,0,0,0,0,0}; /*Impulse Response Co-efficient*/
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
Calculations:
x[n] = [1 2 3 4]—> L1=4 h[n] = [1 2 3]—> L2=3
L=L1+L2-1 => 4+3-1=>6 L=6
y[n]=x[n].h[n]
∞
y[n]= Σ x[n].h[n]
-∞
Now,
5
y[n]= Σ x[n].h[n]
K=0
5
n=0, y[0] = Σ x[k].h[0-k]
K=0
y[0] = 1
5
n=1, y[1] = Σ x[0].h[1-k]
K=0
=>(1)(2)+(2)(1) =>2+2
y[1] = 4
5
n=2, y[2] = Σ x[0].h[2-k]
K=0
5
n=3, y[3] = Σ x[0].h[3-k]
K=0
5
n=4, y[4] = Σ x[0].h[4-k]
K=0
5
n=5, y[5] = Σ x[0].h[5-k]
K=0
=>(4)(3) =>12
y[5]= 12
y[n] = [1 4 10 16 17 12]
NOTE:
Procedure is given in page number 48 to run code composer studio v6.1.3. Follow the steps.