SP Codes 1-5
SP Codes 1-5
1 discrete
%Unit Imp seq
function[y,n]=impseq(a,b,c)
n=a:b;
y=(n-c)==0;
stem(n,y)
%Unit Step seq
function[y,n]=stepseq(a,b,c)
n=a:b;
y=(n-c)>=0;
stem(n,y)
%Unit Ramp seq
function[y,n]=rampseq(a,b,c)
n=a:b;
y=((n-c)>=0).*(n-c);
stem(n,y)
%Real exp a^n
function[y,n]=exp(a,b,c)
n=b:c
y=exp(a^n);
stem(n,y)
%Complex exp e^jwn
n=-10:10;
y=exp(j*0.3*n);
subplot(211); stem(n,real(y))
subplot(212); stem(n,imag(y))
figure;
subplot(211); stem(n,abs(y))
subplot(212); stem(n,phase(y)*180/pi)
%Sin
n=-10:10;
y=sin(n)
stem(n,y)
%Exp seq
B=1;
r=0.85;
n=-10:10;
x=B*r.^n;
subplot(311); stem(n,x,'filled'); xlabel('Time(n)'); ylabel('x[n]');
x=B*r.^(-n);
subplot(312); stem(n,x,'filled'); xlabel('Time(n)'); ylabel('x[n]');
x=B*r.^abs(n);
subplot(313); stem(n,x,'filled'); xlabel('Time(n)'); ylabel('x[n]');
%1.2 continous
%Step sig
function[y,t]=stepsig(a,b,c)
t=a:0.01:b;
y=(n-c)>=0;
plot(t,y)
%Ramp sig
function[y,t]=ranpsig(a,b,c)
t=a:0.01:b;
y=((n-c)>=0).*(n-c);
plot(t,y)
%Real exp sig
function[y,t]=expsig(a,b,c)
t=b:0.01:c;
y=exp(a*t);
plot(t,y)
%Comp exp sig
t=-10:0.01:10;
y=exp(j*w*t);
subplot(211); plot(t,abs(y))
subplot(212); plot(t,phase(y)*180/pi)
%sin
t=-10:0.01:10;
y=sin(t);
plot(y,t)
%3.2 plot poles n zeros, find trans func, partial frac expansion, freq res
clc; clear all; close all;
num=[1 0 -1]
den=[1 0 -0.81]
zplane(num,den)
sys=tf(num,den,-1)
[R,P,K]=residuez(num,den)
[b,a]=residuez(R,P,K)
figure;
omega=0:pi/100:pi;
y=freq(num,den,omega);
subplot(211); stem(omega/pi,abs(y)); xlabel('freq in pi units');
ylabel('Magnitude'); title('mag resp');
subplot(212); stem(omega/pi,phase(y)/pi); xlabel('freq in pi units');
ylabel('Phase'); title('phase resp');