// 1) verification of sampling
t=-5:.1:5
T=4
fm=1/T
x=cos(2*pi*fm*t)
fs1=1.6*fm
fs2=2*fm
fs3=33*fm
subplot(2,2,1)
plot(t,x)
xlabel('time');
ylabel('x(t)');
title('ct signal');
n1=-4:1:4;
xn1=cos(2*pi*n1*(fm/fs1))
subplot(2,2,2)
stem(n1,xn1)
xlabel('n');
ylabel('xn');
title('dt signal with fs<2fm');
n2=-5:1:5;
xn2=cos(2*pi*n2*(fm/fs2))
subplot(2,2,3)
stem(n2,xn2)
xlabel('n');
ylabel('nx');
title('dt signal with fs=2fm');
n3=-20:1:20;
xn3=cos(2*pi*n3*(fm/fs3))
subplot(2,2,4)
stem(n3,xn3)
xlabel('n');
ylabel('xn');
title('dt signal with fs>2fm');
// 2) study of DFT properties
x=[1 2 3 4]
h=[1 1 1 1]
y=cconv(x,h,4)
x1=fft(x,4)
x2=fft(h,4)
z=ifft(x1.*x2)
Y1=x+h
z1=ifft(x1+x2)
// 3) 4 point circular convolution
x=input('enter x(n)');
h=input('enter h(n)');
N=input('enter N point DFT');
y=cconv(h,x,N)
z=conv(x,h)
// 4) To find interpolation and decimation
M=input('enter the interpolation and decimation factor');
N=50;
n=0:N-1;
x=sin(2*pi*0.043*n)+sin(2*pi*0.031*n);
subplot(3,1,1)
stem(n,x(1:N))
m=0:(N/M)-1;
y=decimate(x,M);
subplot(3,1,2)
stem(m,y(1:N/M))
y=interp(x,M);
subplot(3,1,3)
m=0:(N*M)-1;
stem(m,y(1:N*M))
// 5) pole and zero
a=[1 .5]
b=[1 -1.8 .72]
[r p k]=residue(a,b)
zplane(a,b)
// 6) FIR filter
wc=1;
N=7;
n=0:1:N-1;
a=(N-1)/2;
hd=sin(wc*(n-a+eps))/(pi*(n-a+eps));
wr=boxcar(N);
hn=hd.*wr;
w=0:0.01:pi;
h=freqz(hn,1,w);
subplot(3,1,1)
plot(w/pi,abs(h));
title('FIR using rectangular window');
wh=hamming(N);
hn1=hd.*wh;
w=0:0.01:pi;
h1=freqz(hn1,1,w);
subplot(3,1,2)
plot(w/pi,abs(h1))
title('FIR using hamming window');
// 7) IIR filter
N=input('enter the order');
fc=input('enter cut-off freq in Hz');
fs=input('enter sampling freq in Hz');
wc=2*fc/fs;
[b,a]=butter(N,wc);
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,abs(h))
xlabel('Normalised freq');
ylabel('abs of h');
title('Design of IIR filter using BLT method');
subplot(2,1,2)
zplane(b,a);
title('pole zero plot')
No comments: