You are on page 1of 9

clear all

clc
syms tau t alpha;
x = exp(-tau);
h = exp(-2*(t-tau));
f = x*h;
y = int(f,tau,0,t);
y = simplify(y)
4
Sistemas lineares invariantes no tempo (SLIT)
U1
• Convolução gráfica:
clear all
clc
t = -1:0.01:5;
x = exp(-t).*u(t);
fig=figure();
p=plot(t,x,’k’);
set(p,’LineWidth’,2);
ylabel(‘x(t)’)
xlabel(‘Tempo (s)’);
fig=figure();
h = exp(-2*t).*u(t);
p=plot(t,h,’k’);
set(p,’LineWidth’,2);
ylabel(‘h(t)’)
xlabel(‘Tempo (s)’);
fig=figure();
t = 0.01:0.01:5;
x = exp(-t).*u(t);
h = exp(-2*t).*u(t);
p=plot(-t,h,’k’,t,x);
set(p,’LineWidth’,2);
legend(‘h(t-\tau)’,’x(\tau)’)
xlabel(‘Tempo (s)’);
t = 0:0.01:5;
fig=figure();
y=conv(h,x);
p=plot(t,y(1:length(t)),’k’);
set(p,’LineWidth’,2);
ylabel(‘y(t)’);
xlabel(‘Tempo (s)’);
Ashutosh Rout
13 Aug 2018

clc;
close all;
%first sequence
x=input('Enter x\n');
l1=input('Enter the lower limit:\n');
u1=input('Enter the upper limit:\n');
x1=l1:1:u1;%limit of sequence x(n)
%second sequence
h=input('Enter h:\n');
l2=input('Enter the lower limit:\n');
u2=input('Enter the upper limit:\n');
h1=l2:1:u2;%limit of sequence h(n)
l=l1+l2;
u=u1+u2;
a=l:1:u;%limit of output sequence y(n)
m=length(x);%length of sequence x(n)
n=length(h);%length of sequence h(n)
X=[x,zeros(1,n)];
subplot(311)
disp('x(n) is:')
disp(x)
stem(x1,x)
xlabel('n')
ylabel('x(n)')
title('First Sequence')
grid on;
H=[h,zeros(1,m)];
subplot(312)
disp('h(n) is:')
disp(h)
stem(h1,h)
xlabel('n')
ylabel('h(n)')
title('Second Sequence')
grid on;
%CONVULATION
for i=1:n+m-1
Y(i)=0;
for j=1:m
if((i-j+1)>0)
Y(i)=Y(i)+(X(j)*H(i-j+1));
else
end
end
end
subplot(313)
disp('y(n) is:')
disp(Y)
stem(a,Y)
xlabel('n')
ylabel('y(n)')
title('Output Sequence')
grid on;

clear all
clc
syms tau t alpha;
x = exp(-tau);
h = exp(-2*(t-tau));
f = x*h;
y = int(f,tau,0,t);
y = simplify(y)
4
Sistemas lineares invariantes no tempo (SLIT)
U1
• Convolução gráfica:
clear all
clc
t = -1:0.01:5;
x = exp(-t).*u(t);
fig=figure();
p=plot(t,x,’k’);
set(p,’LineWidth’,2);
ylabel(‘x(t)’)
xlabel(‘Tempo (s)’);
fig=figure();
h = exp(-2*t).*u(t);
p=plot(t,h,’k’);
set(p,’LineWidth’,2);
ylabel(‘h(t)’)
xlabel(‘Tempo (s)’);
fig=figure();
t = 0.01:0.01:5;
x = exp(-t).*u(t);
h = exp(-2*t).*u(t);
p=plot(-t,h,’k’,t,x);
set(p,’LineWidth’,2);
legend(‘h(t-\tau)’,’x(\tau)’)
xlabel(‘Tempo (s)’);
t = 0:0.01:5;
fig=figure();
y=conv(h,x);
p=plot(t,y(1:length(t)),’k’);
set(p,’LineWidth’,2);
ylabel(‘y(t)’);
xlabel(‘Tempo (s)’);
Ashutosh Rout
13 Aug 2018

clc;
close all;
%first sequence
x=input('Enter x\n');
l1=input('Enter the lower limit:\n');
u1=input('Enter the upper limit:\n');
x1=l1:1:u1;%limit of sequence x(n)
%second sequence
h=input('Enter h:\n');
l2=input('Enter the lower limit:\n');
u2=input('Enter the upper limit:\n');
h1=l2:1:u2;%limit of sequence h(n)
l=l1+l2;
u=u1+u2;
a=l:1:u;%limit of output sequence y(n)
m=length(x);%length of sequence x(n)
n=length(h);%length of sequence h(n)
X=[x,zeros(1,n)];
subplot(311)
disp('x(n) is:')
disp(x)
stem(x1,x)
xlabel('n')
ylabel('x(n)')
title('First Sequence')
grid on;
H=[h,zeros(1,m)];
subplot(312)
disp('h(n) is:')
disp(h)
stem(h1,h)
xlabel('n')
ylabel('h(n)')
title('Second Sequence')
grid on;
%CONVULATION
for i=1:n+m-1
Y(i)=0;
for j=1:m
if((i-j+1)>0)
Y(i)=Y(i)+(X(j)*H(i-j+1));
else
end
end
end
subplot(313)
disp('y(n) is:')
disp(Y)
stem(a,Y)
xlabel('n')
ylabel('y(n)')
title('Output Sequence')
grid on;

function [y] = myconv( x,h )


m=length(x);
n=length(h);
x=[x,zeros(1,n)];
h=[h,zeros(1,m)];
for i=1:n+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
\

x = input('Enter x: ');
h = input('Enter h: ') ;
Ni = length(x);
Nh = length(h);
y = zeros(1,Ni+Nh);
t = zeros(1,Nh);
for i = 1:Ni+Nh-1
if i<=Ni
t(1)= x(i);
for j = 1:Nh
y(i) = y(i) + h(j)*t(j);
end
for k = Nh:-1:2
t(k) = t(k-1);
end

else
t(1)= 0;
for j = 1:Nh
y(i) = y(i) + (h(j)*t(j));
end

for k = Nh:-1:2
t(k) = t(k-1);
end

end

end
stem(y);

X = input('Enter x: '); %input vector X and H


H = input('Enter h: ') ;
LenX = length(X); %defining their lenghts
LenH = length(H);
y = zeros(1,LenX+LenH); %defing vector y of zeroes and of size
% lenth of X + length of H
t = zeros(1,LenH); % definign a vector t of same length as H
for i = 1:LenH+LenX-1 % Running a for loop from 1 to length of Y -1
if i<=LenX % till I IS Lesser then length of X i.e overlap about to begin
t(1)= X(i); % put x(i) on t(1) later it is shifted forwards in the vector t i.e. later t(2)=t(1)
for j = 1:LenH % in the if condition a for loop from 1 to length of H
y(i) = y(i) + H(j)*t(j); % summing for all H(j)*t(j) and putting it at y(1) or y(2) or Y(i) in first iteration
% i.e. for i=1 only firt multiplication would
% be non zero rest all zeroes.
end
for k = LenH:-1:2 % shifting old value of t(i) to t(i+1) now there would me 1+ non zeroes values in t
% this cycle would continue until i is lesser then
% length X i.e. overlap increasing every iteration less
% and less non zero vales in t every iteration
t(k) = t(k-1);
end
else % now when all of the T is non zero which means 100% overlap in else overlap would start to decrease
between T and H
% T is basically X
t(1)= 0;
for j = 1:LenH % Now we start filling up Zeroes in T i.e. overlap began to decrease now and each iteration it
would decrease
% i.e T moving to left until there is no more
% over lap
y(i) = y(i) + (H(j)*t(j)); % in this for loop we multiply all respective vales of h and t and add the
% putting it at y(1) or y(2) or Y(i) in first iteration
end
for k = LenH:-1:2 %% here just like similar loop above t where we were filling up t with vales of x
%now we are filling up zeroos in t i.e. over lap decreasing
t(k) = t(k-1);
end
end
end
ly=length(y)
indices=[ly]
for i=1:ly
indices(i)=i;
end
disp (y); %displays vector y.
disp (indices); % displays vector indices.
stem(y);
ylabel('Y[n]');
xlabel('[n]');
title('Convolution without conv function');

clc
clear all
close all
x=input('Enter the first sequence: ');
l1=input('Enter the lower limit: ');
u1=input('Enter the upper limit: ');
x1=l1:1:u1;
h=input('Enter the second sequence: ');
l2=input('Enter the lower limit: ');
u2=input('Enter the upper limit: ');
h1=l2:1:u2;
l=l1+l2;
u=u1+u2;
n=l:1:u;
s=numel(n);
i=1;
for i=1:s
y(i)=0;
for k=1:numel(x)
if (i+1-k)<=0
y(i)=y(i)+(x(k)*0);
else if (i+1-k)>numel(h)
y(i)=y(i)+(x(k)*0);
else
y(i)=y(i)+(x(k)*h(i+1-k));
k=k+1;
end
end
end
i=i+1;
end
disp(y);
subplot(2,2,1);stem(x1,x);
title('First sequence');xlabel('n');ylabel('x(n)');
subplot(2,2,2);stem(h1,h);
title('Second Sequence');xlabel('n');ylabel('h(n)');
subplot(2,2,[3 4]);stem(n,y);
title('Convoluted sequence');xlabel('n');ylabel('y(n)');

function y=my_conv(x,h)
x2=h;
lx=length(x);
lh=length(h);
if lx>lh
x2=[x2 zeros(1,lx-lh)];
else
x=[x zeros(1,lh-lx)];
end
y=zeros(1,lx+lh-1);
x=fliplr(x);
for i=1:length(y)
if i<=length(x)
y(i)=sum(x(1,length(x)-i+1:length(x)).*x2(1,1:i));
else
j=i-length(x);
y(i)=sum(x(1,1:length(x)-j).*x2(1,j+1:length(x2)));
end
end
figure
stem(y);

% SIMPLE CONVOLUTION FUNCTION conv(x,h)


% Lucas Emanuel Batista dos Santos
%-
% Receive two vectors and show on screen a new vector resultant of
% convolution operation
function simple_conv(f, g)
% Transform the vectors f and g in new vectors with the same length
F = [f,zeros(1,length(g))];
G = [g,zeros(1,length(f))];
% FOR Loop to put the result of convolution between F and G vectors
% in a new vector C. According to the convolution operation characteristics,
% the length of a resultant vector of convolution operation between two vector
% is the sum of vectors length minus 1
for i=1:length(g)+length(f)-1
% Create a new vector C
C(i) = 0;
% FOR Loop to walk through the vector F ang G
for j=1:length(f)
if(i-j+1>0)
C(i) = C(i) + F(j) * G(i-j+1);
else
end
end
end
% Show C vector on screen
C
end

You might also like