You are on page 1of 3

Unit step

function[x,n]=unitstep(n0,n1,n2)
n=[n1:n2];
x=[(n-n0)>=0];
stem(n,x);
[x,n]=ustpfn(0,0,20)
Exponential
function[x,n]=exponential(n0,n1,n2)
n=[n1:n2];
x=(0.6).^n;
stem(n,x);
[x,n]=expfn(0.6,0,20)
Sinusoidal
function[x,n]=sinusoidal(n0,n1,n2)
n=[n1:n2];
x=cos(n0*pi*n);
plot(n,x);
[x,n]=sinfn(0.1,0,60)
Convolution
function[y,ny]=conv_m(x,nx,h,nh)
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
y=conv(x,h);
X=[1,2,3,1];
n1=[0:3];
N1=length(X);
h=[1,1,1];
n2=[0:2];
N2=length(h);
y=conv(X,h);
k=min(min(n1),min(n2));
n=k:1:(N1+N2+k)-2;
stem(n,y);
title('convolution');
xlabel('n');
ylabel('y(n)');
Stability
b=[1];
a=[1,-1,0.9];
x=impls(0,-20,120);
n=[-20:120];
h=filter(b,a,x);
subplot(211);
stem(n,h);
title('impulse sequence');
xlabel('n');
ylabel('h(n)');
2) b=[1];
a=[1,-1,0.9];
n=[-20:100];
x=unitstep(0,-20,100);
s=filter(b,a,x);
subplot(212)
stem(n,s);
title('step response');
xlabel('n');

ylabel('h(n)');
3) sum (abs(h))
z=roots(a)
magz=abs(z)
Evenod
n=[0:10];
x=stepseq (0,0,10)-stepseq(10,0,10);
[xe,xo,m]=evenodd(x,n);
subplot(221)
stem(n,x);
title('even and odd');
xlabel('n');
ylabel('x(n)');
subplot(222)
stem(m,xe);
title('even sequence');
xlabel('m');
ylabel('xe');
subplot(223)
stem(m,xo);
title('odd sequence');
xlabel('m');
ylabel('xo');

Freqz
function[db,mag,pha,grd,W]=freqz_m(b,a)
[H,W]=freqz(b,a);
H=(H(1:1:501));
W=(W(1:1:501));
mag=abs(H);
db=20*log10((mag+eps)/max(mag));
pha=angle(H);
Ideal_lp
function[hd]=ideal_lp(wc,M)
alpha=(M-1)/2;
n=[0:1:M-1];
m=n-alpha+eps;
hd=sin(wc*m)./(pi*m);
Freqs
function[db,mag,pha,W]=freqs_m(b,a,wmax)
w=[0:1:500]*wmax/500;
H=freqs(b,a,w);
mag=abs(h);
db=20*log10((mag+eps)/max(mag));
pha=angle(H);

You might also like