You are on page 1of 21

% P2.

1a
n = [0:25];
x1 = zeros(1,26);
for m=0:10,
x1 = x1 + (m-1).*(impseq(2.*m,0,25)-impseq(2.*m+1,0,25));
end
subplot(3,2,1);
stem(n,x1); title('Sequence in Problem 2.1a')
% P2.1b
n = [-25:25];
x2 = n.^2.*(stepseq(-5,-25,25)-stepseq(6,-25,25)) + 10*impseq(0,-25,25) +
20*0.5.^n.*(stepseq(4,-25,25)-stepseq(10,-25,25));
subplot(3,2,2);
stem(n,x2); title('Sequence in Problem 2.1b')
% P2.1c
n = [0:20];
x3 = 0.9.^n.*cos(0.2*pi.*n + pi/3);
subplot(3,2,3);
stem(n,x3); title('Sequence in Problem 2.1c')
% P2.1d
n = [0:100];
x4 = 10.*cos(0.008*pi.*n.^2) + randn(size(n));
subplot(3,2,4);
stem(n,x4); title('Sequence in Problem 2.1d')
% P2.1e
x5 = [2,1,2,3];
x5 = x5' * ones(1,5);
% Plots 5 periods
x5 = (x5(:))';
n = [0:size(x5)];
subplot(3,2,5);
stem(x5);
title('Sequence in Problem 2.1e')

% P2.2
x = [1,-2,4,6,-5,8,10];
n = [-4:2];
subplot(3,2,1); stem(n,x); title('Original Sequence');
% P2.2a
[x11,n11] = sigshift(x,n,-2);
[x12,n12] = sigshift(x,n,4);
[x1,n1] = sigadd(3*x11,n11,x12,n12);
[x1,n1] = sigadd(x1,n1,-2*x,n);
subplot(3,2,2); stem(n1,x1); title('Sequence in Problem 2.2a');
% P2.2b
[x21,n21] = sigshift(x,n,-5);
[x22,n22] = sigshift(x,n,-4);
[x2,n2] = sigadd(5*x21,n21,4*x22,n22);
[x2,n2] = sigadd(x2,n2,3*x,n);
subplot(3,2,3); stem(n2,x2); title('Sequence in Problem 2.2b');
% P2.2c
[x31,n31] = sigshift(x,n,-4);
[x32,n32] = sigshift(x,n,1);
[x33,n33] = sigmult(x31,n31,x32,n32);
[x31,n31] = sigfold(x,n);
[x31,n31] = sigshift(x31,n31,2);
[x32,n32] = sigmult(x31,n31,x,n);
[x3,n3] = sigadd(x33,n33,x32,n32);
subplot(3,2,4); stem(n3,x3); title('Sequence in Problem 2.2c');
% P2.2d
[x41,n41] = sigshift(x,n,-2);
x42 = cos(0.1*pi*n);
[x42,n42] = sigmult(x42,n,x41,n41);
x43 = 2*exp(0.5*n);
[x41,n41] = sigmult(x43,n,x,n);
[x4,n4] = sigadd(x42,n42,x41,n41);
subplot(3,2,5); stem(n4,x4); title('Sequence in Problem 2.2d');
% P2.2e
x5 = zeros(size(n));
for k = 1:5,
[x51,n51] = sigshift(x,n,k);
x52 = n.*x51;
x5 = sigadd(x5,n51,x52,n51);
end
subplot(3,2,6); stem(n51,x5); title('Sequence in Problem 2.2e');

% P2.3a
In order for a sequence to be periodic ? 0 has to be a rational multiple
of 2p, i.e. ? 0 = (K/N)2p
% P2.3b
n = -20:20;
x = cos (0.3*pi*n);
% Periodic Sequence T = 20/3
subplot(2,1,1); plot(n,x,'ko-');title('cos(0.3\pin)');xlabel('n');
% P2.3c
x = cos (0.3*n);
% Non-Periodic Sequence
subplot(2,1,2); plot(n,x,'ko-');title('cos(0.3n)');xlabel('n');

% P2.4
x = [1,-2,4,6,-5,8,10];
n = [-4:2];
% P2.4a
[x11,n11] = sigshift(x,n,-2);
[x12,n12] = sigshift(x,n,4);
[x1,n1] = sigadd(3*x11,n11,x12,n12);
[x1,n1] = sigadd(x1,n1,-2*x,n);
[xe,xo,m] = evenodd(x1,n1);
figure(1);
subplot(2,2,1); stem(n1,x1); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

% P2.4b
[x21,n21] = sigshift(x,n,-5);
[x22,n22] = sigshift(x,n,-4);
[x2,n2] = sigadd(5*x21,n21,4*x22,n22);
[x2,n2] = sigadd(x2,n2,3*x,n);
[xe,xo,m] = evenodd(x2,n2);
figure(2);
subplot(2,2,1); stem(n2,x2); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

% P2.4c
[x31,n31] = sigshift(x,n,-4);
[x32,n32] = sigshift(x,n,1);
[x33,n33] = sigmult(x31,n31,x32,n32);
[x31,n31] = sigfold(x,n);
[x31,n31] = sigshift(x31,n31,2);
[x32,n32] = sigmult(x31,n31,x,n);
[x3,n3] = sigadd(x33,n33,x32,n32);
[xe,xo,m] = evenodd(x3,n3);
figure(3);
subplot(2,2,1); stem(n3,x3); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

% P2.4d
[x41,n41] = sigshift(x,n,-2);
x42 = cos(0.1*pi*n);
[x42,n42] = sigmult(x42,n,x41,n41);
x43 = 2*exp(0.5*n);
[x41,n41] = sigmult(x43,n,x,n);
[x4,n4] = sigadd(x42,n42,x41,n41);
[xe,xo,m] = evenodd(x4,n4);
figure(4);
subplot(2,2,1); stem(n4,x4); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

% P2.4e
x5 = zeros(size(n));
for k = 1:5,
[x51,n51] = sigshift(x,n,k);
x52 = n.*x51;
x5 = sigadd(x5,n51,x52,n51);
end
[xe,xo,m] = evenodd(x5,n51);
figure(5);
subplot(2,2,1); stem(n51,x5); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

% P2.5
n = 0:10;
x = 10*exp(-j*0.4*pi*n);
[xe, xo, m] = evenoddcomplex(x,n);
subplot(3,1,1); stem(n,real(x),'ko'); title('Real Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(3,1,2); stem(m,real(xe),'ko'); title('Real Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(3,1,3); stem(m,real(xo),'ko'); title('Real Odd Part')
xlabel('n'); ylabel('xo(n)');
figure(2);
subplot(3,1,1); stem(n,imag(x),'ko'); title('Imaginary Original
Sequence')
xlabel('n'); ylabel('x(n)');
subplot(3,1,2); stem(m,imag(xe),'ko'); title('Imaginary Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(3,1,3); stem(m,imag(xo),'ko'); title('Imaginary Odd Part')
xlabel('n'); ylabel('xo(n)');

function [y,m] = dnsample(x,n,M)


% Implements downsampling on x by a factor of M
% with careful attention to the origin of the time axis at n = 0
% For Example
% [y,m] = dnsample(x,n,M);
index = find (n==0);
x1 = x(1:index);
x1 = fliplr(x1);
y1 = downsample(x1,M);
y1 = fliplr(y1);
temp = size(y1);

m1 = 1:temp(1,2)-1;
m1 = -fliplr(m1);
x2 = x(index:end);
y2 = downsample(x2,M);
y = [y1(1:end-1),y2];
temp = size(y2);
m2 = 0:temp(1,2)-1;
m = [m1,m2];
% P2.6a
n = -50:50;
x = sin(0.125*pi*n);
subplot(2,2,1); plot(n,x,'ko-'); title('Original Signal sin(0.125\pin)');
[y,m] = dnsample(x,n,4);
subplot(2,2,3); plot(m,y,'ko-');
title('Down-Sampled Signal by a factor of 4');
axis([m(1),m(end),-1,1]);
% P2.6b
x = sin(0.5*pi*n);
subplot(2,2,2); plot(n,x,'ko-'); title('Original Signal sin(0.5\pin)');
[y,m] = dnsample(x,n,4);
subplot(2,2,4); plot(m,y,'ko-');
title('Down-Sampled Signal by a factor of 4');
axis([m(1),m(end),-1,1]);

We must be careful at downsampling a signal, since we can lose


information, like in the second case when we decimate a higher frequency
signal. In this situation we must choose a smaller decimation factor in
order to preserve the quality of the original signal.

% P2.7
clear; clc;
n1 = 0:20;
x1 = 0.9.^n1;
subplot(3,2,1); stem(n1,x1,'ko'); title('First given sequence x1(n)');
axis([-20 20 0 1]);
[x1f,n1f] = sigfold(x1,n1);
% obtain x1(-n)
n2 = -20:0;
x2 = 0.8.^(-n2);
subplot(3,2,2); stem(n2,x2,'ko'); title('Second given sequence x2(n)');
axis([-20 20 0 1]);
[x2f,n2f] = sigfold(x2,n2);
% obtain x2(-n)
[r,nr] = conv_m(x1,n1,x1f,n1f);
% auto-correlation
subplot(3,2,3); stem(nr,r,'ko'); title('Auto-Correlation x1(n)*x1(-n)');
[r,nr] = conv_m(x2,n2,x2f,n2f);
% auto-correlation
subplot(3,2,4); stem(nr,r,'ko'); title('Auto-Correlation x2(n)*x2(-n)');
[r,nr] = conv_m(x1f,n1f,x2,n2);
% cross-correlation
subplot(3,1,3); stem(nr,r,'ko'); title('Cross-Correlation');

It is observed that since x1(n) is very similar to x1(-n) at n = 0, so


the autocorrealation sequence finds its peak at n=0. The same can be said
about the sequence x2. From the construction of the cross-correlation,
which peaks at n = -5, it follows that x2(n) is similar to x1(n+5).

% P2.8
n = 0:1;
x = cos(0.2*pi*n) + 0.5*cos(0.6*pi*n);
a = 0.1;
k = 50;
[y,ny] = sigshift(x,n,k);
y = a*y;
[y,ny] = sigadd(y,ny,x,n);
subplot(2,2,1); stem(n,x,'k'); title('Given Sequence');
subplot(2,2,2); stem(ny,y,'k'); title('Delayed Signal');
[yf,nyf] = sigfold(y,ny);
% Folded signal
[ry,nry] = conv_m(yf,nyf,y,ny);
% auto-correlation
subplot(2,2,3); stem(nry,ry,'k'); title('Autocorrelation ryy');
[xf,nf] = sigfold(x,n);
% Folded signal
[rx,nrx] = conv_m(xf,nf,x,n);
% auto-correlation
subplot(2,2,4); stem(nrx,rx,'k'); title('Autocorrelation rxx');

By observing ryy we can estimate the values of a and k, specially the


delay is very notorious in the correlation graph, because there are k
values close to zero in both sides of the plot.

%P2.9b
%T1[x(n)]=2^x(n)
%x(n)=random sequence
nrand=[0:100];xrand=rand(size(nrand));
t1=2.^xrand
[x1,n1]=sigshift(t1,n,50); %x(n-k) k=50
[x2,n2]=sigfold(t1,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t1,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
figure(2);
subplot(3,1,1); stem(m,y);title('Autocorrelation ryy');xlabel('m');
%T2[x(n)]=3x(n)+4
%x(n)=random sequence
nrand=[0:100];xrand=rand(size(nrand));
t2=3*xrand+4
[x1,n1]=sigshift(t2,n,50); %x(n-k) -> k=50
[x2,n2]=sigfold(t2,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t2,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
subplot(3,1,2); stem(m,y);title('Autocorrelation ryy');xlabel('m');
%T3[x(n)]=x(n)+2x(n-1)-x(n-2)
%x(n)=Random Sequence
nrand=[0:100];xrand=rand(size(nrand));
[xa,nxa]=sigshift(xrand,nrand,1);
[xb,nxb]=sigshift(xrand,nrand,2);
[xa,nxa]=sigadd(2*xa,nxa,-1*xb,nxb);
[t3,n]=sigadd(xrand,nrand,xa,nxa);
[x1,n1]=sigshift(t3,n,50); %x(n-k) -> k=50
[x2,n2]=sigfold(t3,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t3,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
subplot(3,1,3); stem(m,y);title('Autocorrelation ryy');xlabel('m');

%P2.9c
%T1[x(n)]=2^x(n)
%x(n)=Gaussian random sequence
nrand=[0:100];xrand=randn(size(nrand))
t1=2.^xrand
[x1,n1]=sigshift(t1,n,50); %x(n-k) k=50
[x2,n2]=sigfold(t1,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t1,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
figure(3);
subplot(3,1,1); stem(m,y);title('Autocorrelation ryy');xlabel('m');
%T2[x(n)]=3x(n)+4
%x(n)=Gaussian random sequence
nrand=[0:100];xrand=randn(size(nrand))
t2=3*xrand+4
[x1,n1]=sigshift(t2,n,50); %x(n-k) -> k=50
[x2,n2]=sigfold(t2,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t2,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
subplot(3,1,2); stem(m,y);title('Autocorrelation ryy');xlabel('m');
%T3[x(n)]=x(n)+2x(n-1)-x(n-2)
%x(n)=Gaussian Random Sequence
nrand=[0:100];xrand=randn(size(nrand));
[xa,nxa]=sigshift(xrand,nrand,1);
[xb,nxb]=sigshift(xrand,nrand,2);
[xa,nxa]=sigadd(2*xa,nxa,-1*xb,nxb);
[t3,n]=sigadd(xrand,nrand,xa,nxa);
[x1,n1]=sigshift(t3,n,50); %x(n-k) -> k=50
[x2,n2]=sigfold(t3,n); %x(-n)
[x3,n3]=sigfold(x1,n1); %x(k-n)
[rxx,nrxx]=conv_m(t3,n,x2,n2);
[rxk,nrkx]=conv_m(x1,n1,x3,n3);
[y,m]=sigadd(rxx,nrxx,0.1*rxk,nrkx);
subplot(3,1,3); stem(m,y);title('Autocorrelation ryy');xlabel('m');

%P2.12
%Commutation Property
%x1(n)*x2(n)=x2(n)*x1(n)
nx=[-20:30]; x1=nx.*(stepseq(-10,-20,30)- stepseq(20,-20,30));
x2=cos(0.1*pi*nx).*(stepseq(0,-20,30)- stepseq(30,-20,30));
%x1(n)*x2(n)
[y1,m1]=conv_m(x1,nx,x2,nx);
figure(1);
subplot(2,2,1);stem(m1,y1,'k');title('x1*x2');xlabel('m');
%x2(n)*x1(n)
[y1,m1]=conv_m(x2,nx,x1,nx);
subplot(2,2,2);stem(m1,y1,'k');title('x2*x1');xlabel ('m');
%Association Property
%[x1(n)*x2(n)]*x3(n)=x1(n)*[x2(n)*x3(n)]
nx=[-20:30]; x1=nx.*(stepseq(-10,-20,30)- stepseq(20,-20,30));
x2=cos(0.1*pi*nx).*(stepseq(0,-20,30)- stepseq(30,-20,30));
x3=1.2.^nx.*(stepseq(-5,-20,30)-stepseq(10,-20,30));
[y1,m1]=conv_m(x1,nx,x2,nx);
[y2,m2]=conv_m(y1,m1,x3,nx);
subplot(2,2,3);stem(m2,y2,'k');title('[x1*x2]*x3');xlabel('m');
[y1,m1]=conv_m(x2,nx,x3,nx);
[y2,m2]=conv_m(x1,nx,y1,m1);;
subplot(2,2,4);stem(m2,y2,'k');title('x1*[x2*x3]');xlabel('m');

%Distribution Property %x1(n)*[x2(n)]+x3(n)]=x1(n)*x2(n)+x1(n)*x3(n)


nx=[-20:30]; x1=nx.*(stepseq(-10,-20,30)- stepseq(20,-20,30));
x2=cos(0.1*pi*nx).*(stepseq(0,-20,30)- stepseq(30,-20,30));
x3=1.2.^nx.*(stepseq(-5,-20,30)-stepseq(10,-20,30));
[y1,m1]=sigadd(x2,nx,x3,nx);
[y2,m2]=conv_m(x1,nx,y1,m1);
figure(2);
subplot(2,2,1);stem(m2,y2,'k');title('x1*[x2+x3]');xlabel('m');
[y1,m1]=conv_m(x1,nx,x2,nx);
[y2,m2]=conv_m(x1,nx,x3,nx);
[y3,m3]=sigadd(y1,m1,y2,m2);
subplot(2,2,2);stem(m3,y3,'k');title('x1*x2+x1*x3]');xlabel('m');
%Identity
%x1(n)*d(n-n0)= x1(n-n0)
nx=[-20:30]; x1=nx.*(stepseq(-10,-20,30)- stepseq(20,-20,30));
%x1(n)*delta(n-n0)
[y1,m1]=impseq(10,-20,30);
[y2,m2]=conv_m(x1,nx,y1,m1);
subplot(2,2,3);stem(m2,y2,'k');title('x1*delta(nn0)'); xlabel('m');
[y1,m1]=sigshift(x1,nx,10);
subplot(2,2,4);stem(m1,y1,'k');title('x1(nn0)]');xlabel('m');
axis([-40 60 -10 20]);

%P2.13
nx = 0:3;
% Index for sequence x(n)
x = 1:4;
% Sequence x(n) = {1,2,3,4}
nh = 0:2;
% Index for impulse h(n)
h = 3:-1:1;
% Sequence h(n) = {3,2,1}
[y,ny] = conv_m(x,nx,h,nh); % Linear Convolution y(n) = h(n)*x(n)
htilde = [h';zeros(size(x)-[0,1])'];
%m = 0:length(htilde)-1;
Hcol = zeros(size(x)+size(h)-[1,1])';
H = htilde;
for k = 1:length(x)-1,
Hcol=circshift(htilde,k);
H=[H,Hcol];
end
ytilde = H*x'; %Performs convolution using Toeplitz matrix
x =
1

14

20

3
2
1
0
0
0

0
3
2
1
0
0

0
0
3
2
1
0

0
0
0
3
2
1

h =
y =
11

H =

A Toeplitz matrix can be defined as follows: It is a matrix of N x M


dimensions, where N is the number of rows (columns of x + columns of h 1) and N is the number of columns of x. In each column the impulse
response h is shifted downwards one place at a time.
The first row is composed by h(1) and is zero-padded to fulfill the
required dimensions. The first column is the vector h, which is also
zero-padded.

%P2.14a
function [ytilde,H]=conv_toe(h,x)
% Linear Convolution using Toeplitz Matrix
% ---------------------------------------% [ytilde,H] = conv_toe(h,x)
% ytilde = output sequence in column vector form
% H = Toeplitz matrix corresponding to sequence h so that y = Hx
% h = Impulse response sequence in row vector form
% x = input sequence in row vector form
%
htilde = [h';zeros(size(x)-[0,1])'];
Hcol = zeros(size(x)+size(h)-[1,1])';
H = htilde;
for k = 1:length(x)-1,
Hcol=circshift(htilde,k);
H=[H,Hcol];
end
%Calculates Toeplitz Matrix
ytilde = H*x'; %Performs convolution using Toeplitz matrix

%P2.14b
nx = 0:3;
% Index for sequence x(n)
x = 1:4;
% Sequence x(n) = {1,2,3,4}
nh = 0:2;
% Index for impulse h(n)
h = 3:-1:1;
% Sequence h(n) = {3,2,1}
[ytilde,H]=conv_toe(h,x);
x =
1

3
2
1
0
0
0

0
3
2
1
0
0

0
0
3
2
1
0

can

verify

h =

H =
0
0
0
3
2
1

ytilde =
3
8
14
20
11
4
Hence we
problem.

the

results

on

the

functions

given

in

the

last

%P2.15
colordef white
b=[1]; a=[1,-0.8];
n=[0:50];x=0.8.^n.*(stepseq(0,0,50));
y=filter(b,a,x);
subplot(2,1,1);stem(n,y,'k');title('Convolution x(n)*x(n) using filter')
[y,m]=conv_m(x,n,x,n);
subplot(2,1,2);stem(m,y,'k');title('Convolution x(n)*x(n) using conv_m')

%P2.16
%y(n)-0.5y(n-1)+0.25y(n-2)=x(n)+2x(n-x)+x(n-3)
a=[1,-0.5,0.25];b=[1,2,1];
x=impseq(0,-10,100);n=[-10:100];
h=filter(b,a,x);
subplot(2,1,1);
stem(n,h,'k');title('Impulse Response');xlabel('n');ylabel('h(n)')
%We determine S|h(n)|
sum(abs(h))
%ans = 6.5714
magz =
0.5000
0.5000
%Which implies that the system is stable.
%If x(n)=[5+cos(0.2pn)+4sin(0.6pn)]u(n),
%the impulse response will show no stability
a=[1,-0.5,0.25];b=[1,2,1];
n=[-10:200];
x=(5+3*cos(0.2*pi*n)+4*sin(0.6*pi*n)).*stepseq(0 ,-10,200);
y=filter(b,a,x);
subplot(2,1,2);
stem(n,y,'k');title('Impulse Response');xlabel('n');ylabel('y(n)')
sum(abs(y))
%ans = 5.3389e+003
magz =
0.5000
0.5000
% We observe that the response is not bounded, since the output is not
close to zero as n approaches infinity.

%P2.17
%Rectangular Pulse
n=[-10:40];x=5*(stepseq(0,-10,40)- stepseq(20,-10,40));
[x1,n1]=sigshift(x,n,1);
[x2,n2]=sigadd(x,n,-1*x1,n1);
subplot(3,2,1);stem(n,x,'k');title('Rectangular Pulse')
subplot(3,2,2);stem(n2,x2,'k');title('Simple Digital Differentiator')
axis([-10,40,-5,5])
%Triangular Pulse
n=[-10:40];x=n.*(stepseq(0,-10,40)stepseq(10,-10,40))+(20n).*(stepseq(10,-10,40)- stepseq(20,-10,40));
[x1,n1]=sigshift(x,n,1);
[x2,n2]=sigadd(x,n,-1*x1,n1);
subplot(3,2,3);stem(n,x,'k');title('Triangular Pulse')
subplot(3,2,4);stem(n2,x2,'k');title('Simple Digital Differentiator')
axis([-10,40,-5,5])
%Sinusoidal Pulse
n=[-10:130];x=sin((pi*n)/25).*(stepseq(0,- 10,130)-stepseq(100,-10,130));
[x1,n1]=sigshift(x,n,1);
[x2,n2]=sigadd(x,n,-1*x1,n1);
subplot(3,2,5);stem(n,x,'k');title('Sinusoidal Pulse')
subplot(3,2,6);stem(n2,x2,'k');title('Simple Digital Differentiator')

You might also like