EEE_4702_Lab_1
EEE_4702_Lab_1
Date & Year: ……………… Section: ……... Group: ……….………… Std. ID: ………………
Procedure:
1. Get the number of samples
2. Generate the unit impulse, unite step by using ‘ONES’ and ‘ZEROS’ matrix commands
3. Generate ramp, sine, cosine, exponential signals using the corresponding general formula
4. Plot the graph
Codes:
n=input('enter the length of ramp sequence ') ; n=input('enter the length of exponential
t=0:n-1 ; sequence') ;
stem(t,t) ; t=0:n ;
ylabel('amplitude ---->') ; a=input('enter the value of a ') ;
xlabel('(c)n ---->') ; y=exp(a*t) ;
title(' ramp sequence ') ; stem(t,y) ;
ylabel('amplitude ---->') ;
xlabel('(d)n ---->') ;
title(' exponential sequence ') ;
5. Sine sequence 6. Cosine sequence
t=0:0.05:pi ; t=0:0.05:pi ;
y=sin(2*pi*t) ; y=cos(2*pi*t) ;
stem(t,y) ; stem(t,y) ;
ylabel('amplitude ---->') ; ylabel('amplitude ---->') ;
xlabel('(e)n ---->') ; xlabel('(f)n ---->') ;
title(' sine sequence ') ; title(' cosine sequence ') ;
Class task 1: Delay any two of the plots by 3 samples and advance any of the other two by 2
samples.
Codes:
clc;
clear all;
close all;
x1=input('enter the scaling value value ')
n=input('enter the N value ') ;
t=0:1:n-1 ;
x=ones(1,n) ;
y=x1*x;
subplot(2,2,1);
stem(t,x) ;
ylabel('amplitude ---->') ;
xlabel('(b)n ---->') ;
title(' unit step sequence ') ;
subplot(2,2,2);
stem(y);
title('scaled sequence');
2. Addition: This is a sample-by-sample addition given by and the length of x1(n) and x2(n) must be the
same.
Code: OUTPUT:
clear all; Enter the first sequence: [2 3 1 4 5]
close all; Enter the second sequence: [1 -1 0 1 -1]
x1=0; Result: 3 2 1 5 4
y1=0;
x=input('ENTER THE FIRST SEQUENCE: ');
subplot(3,1,1);
stem(x);
title('X');
y=input('ENTER THE SECOND SEQUENCE:
');
subplot(3,1,2);
stem(y);
title('Y');
l1= length(x);
l2=length(y);
l3=l1-l2;
if l3>0
y= [y,zeros(1,l3)];
elseif l3<0
x=[x,zeros(1,abs(l3));
else
disp('doable')
end
z=x+y;
disp(z)
subplot(3,1,3);
stem(z);
title('Z=X+Y');
3. Subtraction:
Code: OUTPUT:
clc; ENTER THE FIRST SEQUENCE: [2 4 6 8]
clear all; ENTER THE SECOND SEQUENCE:[1 3 5 7]
close all; subtracted sequence 2 4 5 5 -5 -7
n11=input('enter the lower boundary of the
first sequence:');
n12=input('enter the upper boundary of the
first sequence:');
n1=-n11:n12;
x=input('ENTER THE FIRST SEQUENCE:');
n21=input('enter the lower boundary of the
second sequence:');
n22=input('enter the upper boundary of the
second sequence:');
n2=n21:n22;
y=input('ENTER THE SECOND
SEQUENCE:');
subplot(3,1,1);
stem(n1,x);
xlabel ('time')
ylabel ('amplitude')
title('FIRST SEQUENCE') ;
axis([-4 4 -5 5]);
subplot(3,1,2);
stem(n2,y);
xlabel ('time')
ylabel ('amplitude')
title('SECOND SEQUENCE');
axis([-4 4 -5 5]);
n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1
) , max ( n2 ) );
% finding the duration of output signal
s1 =zeros(1,length (n3) );
s2 =s1;
s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1
) )==1 ) )=x;
% signal x with the duration of output signal
'sub'
s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max (
n2 ))==1) )=y;
% signal y with the duration of output signal
'sub'
sub=s1 - s2;
% subtraction
disp('subtracted sequence')
disp(sub)
subplot(3,1,3)
stem(n3,sub)
xlabel ('time')
ylabel ('amplitude')
Code:
clc;
clear all;
close all;
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n1=-n11:n12;
x=input('ENTER THE FIRST SEQUENCE:');
n21=input('ENTER THE LOWER BOUNDARY OF THE SECOND SEQUENCE:');
n22=input('ENTER THE UPPER BOUNDARY OF THE SECOND SEQUENCE:');
n2=n21:n22;
y=input('ENTER THE SECOND SEQUENCE:');
subplot(3,1,1);
stem(n1,x);
xlabel ('time')
ylabel ('amplitude')
title('FIRST SEQUENCE') ;
axis([-4 4 -5 5]);
subplot(3,1,2);
stem(n2,y);
xlabel ('time')
ylabel ('amplitude')
title('SECOND SEQUENCE');
axis([-4 4 -5 5]);
n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1 ) , max ( n2 ) );
% finding the duration of output signal (out)
s1 =zeros(1,length (n3) );
s2 =s1;
s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1 ) )==1 ) )=x;
% signal x with the duration of output signal 'mul'
s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max ( n2 ))==1) )=y;
% signal y with the duration of output signal 'mul'
mul=s1 .* s2;
% multiplication
disp('MULTIPLIED SEQUENCE')
disp(mul)
subplot(3,1,3)
stem(n3,mul)
xlabel ('time')
ylabel ('amplitude')
OUTPUT:
5. Shifting
Code:
clc;
clear all;
close all;
n1=input('Enter the amount to be delayed');
n2=input('Enter the amount to be advanced');
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n=n11:n12;
x=input('ENTER THE SEQUENCE');
subplot(3,1,1);
stem(n,x);
title('Signal x(n)');
m=n+n1;
y=x;
subplot(3,1,2);
stem(m,y);
title('Delayed signal x(n-n1)');
t=n-n2;
z=x;
subplot(3,1,3);
stem(t,z);
title('Advanced signal x(n+n2)');
OUTPUT:
Code:
clc;
clear all;
close all;
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n=n11:n12;
x=input('ENTER THE SEQUENCE');
subplot(2,1,1)
stem(n,x);
axis([-3 3 -5 5]);
title('Signal x(n)');
c=fliplr(x);
y=fliplr(-n);
disp('FOLDED SEQUENCE')
disp(c)
subplot(2,1,2);
stem(y,c);
axis([-3 3 -5 5]);
title('Reversed Signal x(-n)') ;
OUTPUT:
a. Autocorrelation
Auto correlation function is a measure of similarity between a signal & its time delayed version. It is
represented with R(k). The auto correlation function of x(n) is given by
R11(k)=R(k)=
Algorithm:
Step III: Find auto correlation using the matlab command xcorr.
clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence')
subplot(1,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
% auto correlation of input sequence
z=xcorr(x,x);
disp('The values of z are = ');
disp(z);
subplot(1,2,2);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');
Output:
b. Cross Correlation
This correlation function is a measure of similarity between a signal & a different one.
clc;
clear all;
close all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=crosscorr(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel(' (a) n --.');
title('input sequence');
subplot(3,1,2);
stem(h);
ylabel('Amplitude --.');
xlabel(' (b) n --.');
title('impulse sequence');
subplot(3,1,3);
stem(fliplr(y));
ylabel('Amplitude --.');
xlabel(' (c) n --.');
title('Cross correlated sequence');
disp('The resultant signal is');
fliplr(y)
OUTPUT:
The resultant signal is Y=1.0000 4.0000 10.0000 20.↑0000 25.0000 24.0000 16.0000
8. Convolution
Convolution is a mathematical operation used to express the relation between input and output of an LTI
system. It relates input, output and impulse response of an LTI system as
y(n)=x(n)∗h(n)
Algorithm:
Step III: Find the convolution y[n] using the matlab command conv.
Code
clc;
clear all;
close all;
x1=input('Enter the first sequence x1(n) = ');
x2=input('Enter the second sequence x2(n) = ');
L=length(x1);
M=length(x2);
N=L+M-1;
yn=conv(x1,x2);
disp('The values of yn are= ');
disp(yn);
n1=0:L-1;
subplot(311);
stem(n1,x1);
grid on;
xlabel('n1--->');
ylabel('amplitude--->');
title('First sequence');
n2=0:M-1; subplot(312);
stem(n2,x2);
grid on;
xlabel('n2--->');
ylabel('amplitude--->');
title('Second sequence');
n3=0:N-1;
subplot(313);
stem(n3,yn);
grid on;
xlabel('n3--->');
ylabel('amplitude--->');
title('Convolved output');
Output:
b) circular convolution
Code:
clc;
clear all;
a = input('enter the sequence x(n) = ');
b = input('enter the sequence h(n) = ');
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-n1))];
for i = 1:N k = i; for j = 1:n2 H(i,j)=x(k)* b(j);
k = k-1; if (k == 0) k = N;
end
end
end
y=zeros(1,N);
M=H;
for j = 1:N
for i = 1:n2
y(j)=M(i,j)+y(j);
end
end
disp('The output sequence is y(n)= ');
disp(y);
stem(y);
title('Circular Convolution');
xlabel('n');
ylabel('y(n) ');
OUTPUT:
Assignments 1:
1. Give a detailed and comprehensive difference between convolution and correlation nothing
carefully their domains of application
2. Where are linear and circular convolution applied and why?
3. Carefully distinguish between a continuous, discrete, and digital signal.
Assignments 2:
Write short notes on the following topics: