P2.4

Let x(n) = {2,4, -3, 1, -5, 4, 7}. Generate and plot the samples (use the stem function) of

the following sequences.

- x1(n) = 2x(n – 3) + 3x(n + 4) – x(n)
- x2 (n) = 4x(4 + n) + 5x(n + 5) + 2x(n)
- x3 (n) = x(n + 3)x(n – 2) + x(1 – n)x(n + 1)
- x4 (n) = 2e0.5𝑛x(n) + cos(0.1πn) x(n + 2) , -10 ≤ n ≤ 10

sigshift.m is required for this which is attached here

```
unction [y,n] = sigshift(x,m,n0)
% implements y(n) = x(n-n0)
% -------------------------
% [y,n] = sigshift(x,m,n0)
%
n = m+n0; y = x;
```

```
% P2.4
%% P0204a: x(n) = [2,4,-3,1,-5,4,7]; -3 <=n <= 3;
% x1(n) = 2x(n - 3) + 3x(n + 4) - x(n)
clc; close all;
n = [-3:3]; x = [2,4,-3,1,-5,4,7];
[x11,n11] = sigshift(x,n,3); % shift by 3
[x12,n12] = sigshift(x,n,-4); % shift by -4
[x13,n13] = sigadd(2*x11,n11,3*x12,n12); % add two sequences
[x1,n1] = sigadd(x13,n13,-x,n); % add two sequences
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0204a');
Hs = stem(n1,x1,'filled'); set(Hs,'markersize',2);
axis([min(n1)-1,max(n1)+1,min(x1)-3,max(x1)+1]);
xlabel('n','FontSize',8);
ylabel('x_1(n)','FontSize',8);
title('Sequence x_1(n)','FontSize',8); ntick = n1;
ytick = [min(x1)-3:5:max(x1)+1];
set(gca,'XTickMode','manual','XTick',ntick);
set(gca,'YTickMode','manual','YTick',ytick);
print -deps2 ../EPSFILES/P0204a;
```

```
%% P0204b: x(n) = [2,4,-3,1,-5,4,7]; -3 <=n <= 3;
% x2(n) = 4x(4 + n) + 5x(n + 5) + 2x(n)
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0204b');
n = [-3:3]; x = [2,4,-3,1,-5,4,7];
[x21,n21] = sigshift(x,n,-4); % shift by -4
[x22,n22] = sigshift(x,n,-5); % shift by -5
[x23,n23] = sigadd(4*x21,n21,5*x22,n22); % add two sequences
[x2,n2] = sigadd(x23,n23,2*x,n); % add two sequences
Hs = stem(n2,x2,'filled'); set(Hs,'markersize',2);
axis([min(n2)-1,max(n2)+1,min(x2)-4,max(x2)+6]);
xlabel('n','FontSize',8); ylabel('x_2(n)','FontSize',8);
title('Sequence x_2(n)','FontSize',8); ntick = n2;
ytick = [-25 -20:10:60 65];
set(gca,'XTickMode','manual','XTick',ntick);
set(gca,'YTickMode','manual','YTick',ytick);
print -deps2 ../EPSFILES/P0204b;
```

```
%% P204c: x(n) = [2,4,-3,1,-5,4,7]; -3 <=n <= 3;
% x3(n) = x(n + 3)x(n - 2) + x(1 - n)x(n + 1)
clc; close all;
n = [-3:3]; x = [2,4,-3,1,-5,4,7]; % given sequence x(n)
[x31,n31] = sigshift(x,n,-3); % shift sequence by -3
[x32,n32] = sigshift(x,n,2); % shift sequence by 2
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply 2 sequences
[x34,n34] = sigfold(x,n); % fold x(n)
[x34,n34] = sigshift(x34,n34,1); % shift x(-n) by 1
[x35,n35] = sigshift(x,n,-1); % shift x(n) by -1
[x36,n36] = sigmult(x34,n34,x35,n35); % multiply 2 sequences
[x3,n3] = sigadd(x33,n33,x36,n36); % add 2 sequences
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0204c');
Hs = stem(n3,x3,'filled'); set(Hs,'markersize',2);
axis([min(n3)-1,max(n3)+1,min(x3)-10,max(x3)+10]);
xlabel('n','FontSize',8); ylabel('x_3(n)','FontSize',8);
title('Sequence x_3(n)','FontSize',8);
ntick = n3; ytick = [-30:10:60];
set(gca,'XTickMode','manual','XTick',ntick);
set(gca,'YTickMode','manual','YTick',ytick);
print -deps2 ../EPSFILES/P0204c;
```

```
%% P0204d: x(n) = [2,4,-3,1,-5,4,7]; -3 <=n <= 3;
% x4(n) = 2*e^{0.5n}*x(n)+cos(0.1*pi*n)*x(n+2), -10 <=n< =10
clc; close all;
n = [-3:3]; x = [2,4,-3,1,-5,4,7]; % given sequence x(n)
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n42,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0204d');
Hs = stem(n4,x4,'filled'); set(Hs,'markersize',2);
axis([min(n4)-1,max(n4)+1,min(x4)-11,max(x4)+10]);
xlabel('n','FontSize',8); ylabel('x_4(n)','FontSize',8);
title('Sequence x_4(n)','FontSize',8);
ntick = n4; ytick = [ -20:10:70];
set(gca,'XTickMode','manual','XTick',ntick);
set(gca,'YTickMode','manual','YTick',ytick);
print -deps2 ../EPSFILES/P0204d;
```

## Leave a comment