You are on page 1of 18

MATLAB CODES Q1.

B
h=[3 2 1 0 0 0]'; x=[1 2 3 4]'; H=zeros(6,4); for i=1:4 %Shifts the contents of h and assign them to ith column H(:,i)=circshift(h,i-1); end

H= 3 0 2 3 1 2 0 1 0 0 0 0 y=H*x y= 3 8 14 20 11 4 Q1.C The matrix H is characterized by h and dimension of x Like H=Toeplitz_C(h,4) Where 4 is the size of vector x. Here size of matrix is (length(h)+length(x)-1)x(length(x)) and H(i,j)=h(i-j+1) where h(k)=0 for k <=0. Here each entry of H depends on i and j but actually it depends on i-j so it is kind of time invariant. Q1.D The first row of H contains 1st value of h i.e h(0) and other values are all 0. The 1st column of H is the vector h itself. Q2.A
function [y , H] = conv_tp(h , x) H =toeplitz([h zeros(1,length(x)-1)], [h(1) zeros(1,length(x)-1)]); y= H*x;

0 0 3 2 1 0

0 0 0 3 2 1

Q2.B h=[3 2 1]; x=[1 2 3 4]'; [y , H] = conv_tp(h , x); Output: y = 3 8 14 20 11 4

H = 3 2 1 0 0 0 Q3.A function y = down_smpl(x,M); Nx=length(x); Cx=floor(N/2)+1; % index of central term of x Ny=ceil(N/M); % no. of terms of y Cy=floor(N2/2)+1 ;% index of middle term of y y(Cy+((1-Cy):(Ny-Cy-1)))=x(Cx+(M*(2-Cy)):M:Cx+(M*(Ny-Cy))); Q3.B Main Code n = -50:1:50; x = sin(0.125*pi*n); % Evaluate sin(0.2 pi n) subplot(2,1,1); H = stem(n,x,'b','filled');% Stem-plot with handle H set(H,'markersize',4); % Change circle size xlabel('n'); ylabel('x(n)'); % Label axis title('Plot of sin(0.125\pi n)'); M=4; y=down_smpl(x,M); n1=down_smpl(n,M); subplot(2,1,2); H1 = stem(n1,y,'b','filled'); set(H1,'markersize',4); % Change circle size xlabel('n1'); ylabel('y(n1)'); % Label axis title('Plot of y'); 0 3 2 1 0 0 0 0 3 2 1 0 0 0 0 3 2 1

Comment on result : The downsample rate is a factor of period of sequence hence the Downampled output is also periodic and it also now contains only 3 values (1,0,-1).All other values are vanished due to downsampling.

Q3.C The code is same as part B just .125 is replaced by .5. The Plot is as given here From the plot we can see that the downsampled values are only the zero values of the original sequence. Here although there seems a pattern in the output but the amplitude is much low (-14 in order of magnitude) which is zero only.

Q4.A Assuming period of cos(2 fn) is N Then cos(2 fn)= cos(2 f(n+N)) 2 fN=2 f = 1/N where N is an integer. Hence f is a rational number with K=1 and N=N the time period. Q4.B
n=-20:1:20; f=0.15; w0=2*pi*f; x=cos(w0*n); N=(2*pi)/w0; xn=cos(0.3*pi*(n+N)); H = stem(n,x,'b','filled'); set(H,'markersize',4); title('Stem Plot of cos(w0n)'); xlabel('n'); ylabel('x(n)');

Here given sequence is periodic which can be found from the values of xn. The fundamental period is N = 20. And f = .15 = 3/20 So N=3 and K = 20. Q4.C
n=-20:1:20; x=cos(.3*n); N=(2*pi)/w0; H = stem(n,x,'b','filled'); set(H,'markersize',4); xlabel('n'); ylabel('x(n)'); title('Stem Plot of cos(.3n)');

From the plot the sequence seems to be periodic but from the actual values of the sequence it is not periodic. It is because f=.3/2 is not a rational number here.

From the plot the sequence seems to be periodic but from the actual values of the sequence it is not periodic. It is because f=.3/2 is not a rational number here. Q5.A x(n)=(.8)^n* u(n) y(n) is the convolution of the x(n) and x(n) then y(n)= (.8)^n*u(n) + (.8)^n*u(n-1)+ (.8)^n*u(n-2)+ ....... + (.8)^n*u(1) +(.8)^n*u(0) Hence y(n) = (n+1) (.8)^n*u(n)

n=-100:1:100; x=(.8.^n).*(n>=0); y1=(n+1).*(.8.^n).*(n>=0); n=-100:1:100; x=(.8.^n).*(n>=0); m=0:1:50; y1=(m+1).*(0.8.^m).*(m>=0); subplot(3,1,1); Hs1 = stem(m,y1,'b','filled'); set(Hs1,'markersize',4); % Change circle size xlabel('m'); ylabel('y1(m)'); % Label axis title('Stem Plot of conv(x,x)'); % Title plot

y2=filter((1),(1 -.8),x); subplot(3,1,2); Hs2 = stem(n,y2,'b','filled'); xlabel('n'); ylabel('y2=filter x'); % Label axis title('Stem Plot of y2'); % Title plot

y=y2(100:150)-y1; n1=100:150; subplot(3,1,3); Hs2 = stem(n1,y,'b','filled'); xlabel('n1'); ylabel('y(n1)'); % Label axis title('Stem Plot of y2-y1'); % Title plot

Part A and Part are not exactly same as we can see from the difference plot. But for most of the time span they are same .

You might also like