Вы находитесь на странице: 1из 9

%%%laplace transform

syms t;

x=exp(-t);

y=x*cos(10*t);

subplot(4,2,1);ezplot(x,[0,5]);

axis([0 5 0 1.1]);title('x(t)');

subplot(4,2,2);ezplot(y,[-1,5]);

axis([0 5 -1.1 1.1]);title('y(t)');

disp('laplace transform of x(t) is')

X=laplace(x)

disp('laplace transform of y(t) is')

Y=laplace(y)

Xm=abs(X);

Ym=abs(Y);

subplot(4,2,3);ezplot(Xm);

title('Magnitue response of X(s)');

subplot(4,2,4);ezplot(Ym);

title('Magnitude response of Y(s)');

% (b)Write a MATLAB program to generate partial fraction expansion in Laplace Transform

num=input('Enter the numerator coefficients: ');

den=input('Enter the denominator coefficients: ');

[r,p,k]=residue(num,den);

disp('Residues in the partial fraction are')

disp(r);

disp('Poles of the system are')

disp(p);
[11]

[221]

%%%%phase response

syms t w;

x=exp(-2*t).*heaviside(t);

subplot(3,1,1);ezplot(x);

title('x(t)=e^-2t');

disp('The fourier transform of x(t) is')

X=fourier(x)

X=simplify(X);

subplot(3,1,2);ezplot(abs(X));

title('Magnitude response of x(t)');

subplot(3,1,3);ezplot(atan(imag(X)/real(X)));

title('Phase Response of x(t)');

%%%step response of a system

n=0:1:10

x=ones(1,length(n));

subplot(3,1,1);

stem(n,x);

title('step input');

num=[0 1 2];

den=[1 -1 2];

%%step response using matlab command

y=filter(num,den,x);

subplot(3,1,2);stem(y);
title('step response using matlab commmand')

%%%step response using analytic equation

y=(4/3)*(2).^n+(1/6)*(-1).^n-(3/2);

subplot(3,1,3);

stem(y);

title('step rsponse using al\nalytical equation');

%%%%%impulse response

syms n z

num=[1 2];

den=[1 -3 -4];

%transfer function

h=tf('z')

Ts=[];

H=tf(num,den,Ts)

%%% impulse response

[h,n]=impz(num,den)

subplot(2,1,1);stem(n,h);

title('impulse respone using matlab command')

%%%%analytical equation of impilse response

ha=1.2*4.^n-0.2*(-1).^n;

subplot(2,1,2);

stem(n,ha)

title ('impulse respone using analytical equation')


% Write a MATLAB program to calculate the DTFT of a sequence

n=-4:1:4;

x=[zeros(1,2) ones(1,5) zeros(1,2)];

k=-4:4;

w=(pi)*k;

X=x*(exp(-1j*pi/100)).^(n'*k);

subplot(3,1,1);stem(n,x);

title('Discrete time n');ylabel('amplitude');

Xm=abs(x);

subplot(3,1,2);

plot(w/pi,Xm);

title('Magnitude of DTFT of rectangular signal');

xlabel('Frequency in pi units');ylabel('Phase');

Xp=phase(X);

subplot(3,1,3);plot(w/pi,Xp);

title('Phase of DTFT of rectangular signal');

xlabel('Frequency in pi units');ylabel('Magnitude');

%%%%%%%%program to calculate dtft of a sequence

n=0:1:100;

x=cos(pi*n/4);

k=-300:300;

w=(pi/100)*k;

X=x*(exp(-j*pi/100)).^(n'*k);

subplot(3,1,1);stem(n,x);
title('sinosodial input signal');

Xm=abs(X);

subplot(3,1,2);plot(w/pi,Xm);

axis([-3 3 0 60]);

title('magnitude of dtft sinsodial signal');

Xp=phase(X);

subplot(3,1,3);plot(w/pi,Xp);

title('phase of DTFT sinsodial signal');

% Write a MATLAB program to find the poles and the residues and pole-zero plot of a given system
function

disp('The input signal is');

disp('X(z)=z^3/((z-0.5)(z-0.75)(z-1))');

syms z;

zer = -0.5;

pol = 0.9*exp(j*2*pi*[-0.3 0.3]')

d=(z-0.5)*(z-0.75)*(z-1);

a1=collect(d);

den=sym2poly(a1);

n=z^3;

a2=collect(n);

num=sym2poly(a2);

[r p k]=residue(num,den);

fprintf('r1=%4.2f\t',num(1));
fprintf('p1=%4.2f\n',den(1));

fprintf('r2=%4.2f\t',num(2));

fprintf('p2=%4.2f\n',den(2));

fprintf('r3=%4.2f\t',num(3));

fprintf('p3=%4.2f\n',den(3));

zplane(zer,pol);

t=0.2;

H=tf('z');

H=tf(num,den,t);

% Fourier Transform

syms t w;

x=2*(heaviside(t+2)-heaviside(t-2));

subplot(2,1,1);ezplot(x,[-2 2]);

axis([-2.5 2.5 0 2.5]);

X=int(x*exp(-1i*w*t),t,-5,5);

X=simplify(X);

disp('Fourier transform of x(t) is');

disp(X);

subplot(2,1,2);ezplot(X);

%ztransform

%%%z transform

syms n w;

x1=n+1;
disp('The input signal is');

disp(x1);

X1=ztrans(x1);

disp('The Z-Transform is');

disp(X1);

X11=iztrans(X1);

disp('The inverse Z-Transform is');

disp(X11);

x2=sin(n*w);

disp('The input signal is');

disp(x2);

X2=ztrans(x2);

disp('The Z-Transform is');

disp(X2);

X22=iztrans(X2);

disp('The inverse Z-Transform is');

disp(X22);

%%%time scaling

t = -5:0.0001:5; % time vector of 5 seconds

x = tripuls (t ,2) ; % triangular pulse of width 2

subplot (3 ,1 ,1)

plot(t ,x ,'r') , grid

title (' Triangular pulse with width of 2 ')

t1 = 2* t ; % new time vector scaled by 2

x1 = tripuls (t1 ,2) ; % scaled triangular pulse


subplot (3 ,1 ,2)

plot(t ,x1 ,'b') , grid

title (' Triangular pulse with width of 1 ')

t3 = 1/2* t; % new time vector scaled by 0.5

x3 = tripuls (t3 ,2) ; % scaled triangular pulse

subplot (3 ,1 ,3)

plot(t ,x3 ,'g ') , grid

title ('Triangular pulse with width of 4 ')

%%%%time shifting

t = -5:0.0001:5; % time vector of 5 seconds

x = tripuls (t ,2) ; % triangular pulse of width 2

subplot (3 ,1 ,1)

plot(t ,x ,'r ')

title ('Unshifted triangular pulse ') , grid

t4 = t -3; % shift the pulse 3 units towards right

x4 = tripuls (t4 ,2) ;

subplot (3 ,1 ,2)

plot(t ,x4 ,'b ')

title (' Triangular pulse shifted 3 units to right') , grid

t5 = t + 3; % shift the pulse three units left

x5 = tripuls (t5 ,2) ;

subplot (3 ,1 ,3)

plot(t ,x5 ,'g ')

title (' Triangular pulse shifted 3 units to left') , grid

%%%amplitude scaling
a=256; % FFT Length

t=0:1/a:(a-1)/a;

s=(sin(2*pi*12*t)+.8*j*sin(2*pi*4.25*t)+.01*randn(size(t)))/2;

s = floor(s*16384)/16384; %Quantized sum of 2 sines plus noise

subplot(211)

plot(t,real(s))

xlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Real Component')

subplot(212)

plot(t,imag(s))

xlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Imag Component')

Вам также может понравиться