Sunteți pe pagina 1din 9

even and odd part of signal.

x1=[1,3,5,7];
subplot(2,2,1);
stem(x1);
title('\bf Graph of original Signal');
xlabel('\bf n');
ylabel('\bf x1(n)');
x2=fliplr(x1);
subplot(2,2,2);
stem(x2);
title('\bf Graph of flipped Signal');
xlabel('\bf n');
ylabel('\bf x2(n)');
even=(x1+x2)/2;
subplot(2,2,3);
stem(even);
title('\bf Graph of Even part of Signal');
xlabel('\bf n');
ylabel('\bf E(n)');
odd=(x1-x2)/2;
subplot(2,2,4);
stem(odd);
title('\bf Graph of Odd part of Signal');
xlabel('\bf n');
ylabel('\bf O(n)');
analog to digital
fc=20;
t=0:1:10;
x1=sin(2*pi*fc*t);
subplot(2,1,1);
plot(t,x1);
xlabel('\bf time');
ylabel('\bf x1(t)');
title('\bf Analog Signal');
fs=100;
f=fc/fs;
n=0:1:10;
y1=sin(2*pi*f*n);
subplot(2,1,2);
stem(n,y1);
xlabel('\bf n');
ylabel('\bf y1(n)');
title('\bf Digital Signal');
linear convolution
x=[1,1,2,3];
subplot(2,2,1);
stem(x);
xlabel('\bf n');
ylabel('\bf x(n)');
title('\bf Original Signal');
h=[2,1,1,4];
subplot(2,2,2);
stem(h);
xlabel('\bf n');
ylabel('\bf h(n)');
title('\bf Impulse Response Signal');

c=conv(x,h);
subplot(2,2,3);
stem(c);
ylabel('\bf c(n)');
xlabel('\bf n');
title('\bf Convoluted Signal');
circular convolution
x=[1,2,2,3];
subplot(2,2,1);
stem(x);
xlabel('\bf n');
ylabel('\bf x(n)');
title('\bf Original Signal');
h=[2,1,3,4];
subplot(2,2,2);
stem(h);
xlabel('\bf n');
ylabel('\bf h(n)');
title('\bf Impulse Response Signal');
c=cconv(x,h);
subplot(2,2,3);
stem(c);
ylabel('\bf c(n)');
xlabel('\bf n');
title('\bf Convoluted Signal');
auto co-rrelation
x=[1,2,3,4];
subplot(2,2,1);
stem(x);
xlabel('\bf n');
ylabel('\bf x(n)');
title('\bf Original Signal');
y=fliplr(x);
subplot(2,2,2);
stem(y);
xlabel('\bf n');
ylabel('\bf y(n)');
title('\bf Flipped Signal');
z=xcorr(x,y);
subplot(2,2,3);
stem(z);
xlabel('\bf n');
ylabel('\bf z(n)');
title('\bf Auto correlated Signal');
cross correlation
n=0:1:10;
x=[1,2,3,4];
subplot(2,2,1);
stem(x);
xlabel('\bf n');
ylabel('\bf x(n)');
title('\bf first signal');
y=[2,3,1,4];
subplot(2,2,2);
stem(y);

xlabel('\bf n');
ylabel('\bf y(n)');
title('\bf second signal');
z=fliplr(y);
w=conv(x,z);
subplot(2,2,3);
stem(w);
xlabel('\bf n');
ylabel('\bf z(n)');
title('\bf Cross co-related signal');
analog band reject filter.
f=100:20:8000;
>> fl=900;
>> fh=1500;
>> k=length(f);
>> for i=1:k;
m(i)=(1/sqrt(1+(f(i)/fh)^2))-(1/sqrt(1+(fl/f(i))^2));
mag(i)=20*log10(m(i));
end;
>> figure;
>> semilogx(f,mag);
title('\bf Magnitude Response of Band Reject filter');
>> xlabel('\bf Frequency');
>> ylabel('\bf Measurement in db');
>> grid on;
analog band pass filter.
f=100:20:8000;
>> fl=900;
>> fh=1500;
>> k=length(f);
>> for i=1:k;
m(i)=(1/sqrt(1+(f(i)/fh)^2))+(1/sqrt(1+(fl/f(i))^2));
mag(i)=20*log10(m(i));
end;
>> figure;
>> semilogx(f,mag);
title('\bf Magnitude Response of Band Pass filter');
>> xlabel('\bf Frequency');
>> ylabel('\bf Measurement in db');
>> grid on;
analog HPF
f=100:20:8000;
>> fl=900;
>> k=length(f);
>> for i=1:k;
m(i)=1/sqrt(1+(fl/f(i))^2);
mag(i)=20*log10(m(i));
end;
>> figure;
>> semilogx(f,mag);
>> title('\bf Magnitude Response of Analog HPF');
>> xlabel('\bf Frequency');
>> ylabel('\bf Measurement in db');
>> grid on;

analog LPF
f=100:20:8000;
>> fh=900;
>> k=length(f);
>> k=length(f);
>> for i=1:k;
m(i)=1/sqrt(1+(f(i)/fh)^2);
mag(i)=20*log10(m(i));
end;
>> figure;
>> semilogx(f,mag);
>> title('\bf Magnitude Response of Analog LPF');
>> xlabel('\bf Frequency');
>> ylabel('\bf Measurement in db');
>> grid on;
Design Bandpass filter using Rectangular & Hamming Window
wc1=0.25*pi;
wc2=0.75*pi;
N=25
M=(N-1)/2
eps=0.001;
n=0:1:N-1;
hd=[sin(wc2*(n-M+eps))-sin(wc1*(n-M+eps))]./(pi*(n-M+eps));
wr=boxcar(N)
hn=hd.*wr'
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h))
hold on
wh=hamming(N)
hn=hd.*wh';
h=freqz(hn,1,w)
plot(w/pi,abs(h),'--');grid;
ylabel('\bf Magnitude');
xlabel('\bf Normalised Frequency');
hold off
Design BRF filter using Rectangular and Hamming Window
wc1=0.25*pi;
wc2=0.75*pi;
N=25
M=(N-1)/2
eps=0.001;
n=0:1:N-1;
hd=[sin(wc1*(n-M+eps))-sin(wc2*(n-M+eps))+sin(pi*(n-M+eps))]./(pi*(n-M+eps));
wr=boxcar(N)
hn=hd.*wr'
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h))
hold on
wh=hamming(N)
hn=hd.*wh';
h=freqz(hn,1,w)

plot(w/pi,abs(h),'--');grid;
ylabel('\bf Magnitude');
xlabel('\bf Normalised Frequency');
hold off
Design Low Pass Filter using Rectangular & Hamming Window
clear all;
wc=0.5*pi;
N=25
M=(N-1)/2
eps=0.001;
n=0:1:N-1;
hd=[sin(wc*(n-M+eps))]./(pi*(n-M+eps));
wr=boxcar(N)
hn=hd.*wr'
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h))
hold on
wh=hamming(N)
hn=hd.*wh';
h=freqz(hn,1,w)
plot(w/pi,abs(h),'--');grid;
ylabel('\bf Magnitude');
xlabel('\bf Normalised Frequency');
hold off
Design of HPF filter using Rectangular & Hamming Window
wc=0.5*pi;
N=25
M=(N-1)/2
eps=0.001;
n=0:1:N-1;
hd=[sin(pi*(n-M+eps))-sin(wc*(n-M+eps))]./(pi*(n-M+eps));
wr=boxcar(N)
hn=hd.*wr'
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h))
hold on
wh=hamming(N)
hn=hd.*wh';
h=freqz(hn,1,w)
plot(w/pi,abs(h),'--');grid;
ylabel('\bf Magnitude');
xlabel('\bf Normalised Frequency');
hold off
Program for Plotting Frequency response of given system:
b=[1,0,.9];
>> a=[1,0,.4];
>> d=[1,-1];
>> f=[1,0,.25];
>> [h,ph]=freqz(b,a);
>> [h1,ph1]=freqz(d,f);
>> subplot(2,2,1);
>> plot(ph/pi,abs(h));

>> xlabel('\bf normalized Frequency');


>> ylabel('\bf Magnitude');
>> subplot(2,2,2);
>> plot(ph1/pi,abs(h1));
ylabel('\bf Magnitude');
>> xlabel('\bf normalized Frequency');
>> subplot(2,2,3);
>> plot(ph/pi,angle(h));
>> xlabel('\bf normalized Frequency');
>> ylabel('\bf Phase in radians');
>> subplot(2,2,4);
>> plot(ph1/pi,angle(h1));
>> xlabel('\bf normalized Frequency');
>> ylabel('\bf Phase in radians');
>> grid on;
Program to find DFT of a Signal
xn=input('enter the input sequence x(n)=')
[N,m]=size(xn);
if m~=1;
xn=xn'
N=m
end
xk=zeros(N,1);
n=0:N-1
for k=0:N-1
xk(k+1)=exp(-j*2*pi*k*n/N)*xn
end
disp('x(k)=');
disp(xk);
k=0:N-1
subplot(1,1,1);
stem(k,abs(xk));
xlabel('\bf k');
ylabel('\bf Magnitude');
title('\bf DFT of Given Signal');
Program to find IDFT of Given Signal
xk=input('enter the input sequence x(k)=')
[N,m]=size(xk);
if m~=1;
xk=xk'
N=m
end
xn=zeros(N,1);
k=0:N-1
for n=0:N-1
xn(n+1)=[exp(j*2*pi*k*n/N)*xk]/N
end
disp('x(n)=');
disp(xn);
n=0:N-1
subplot(1,1,1);
stem(n,abs(xn));
xlabel('\bf k');
ylabel('\bf Magnitude');
title('\bf IDFT of Given Signal');

Program for Fast Fourier Transform


x=[1,2,3,4];
subplot(2,1,1);
stem(x);
xlabel('\bf n');
ylabel('\bf x(n)');
title('\bf Input Signal');
xk=fft(x);
subplot(2,1,2);
stem(abs(xk));
title('\bf FFT of Input Signal');
Program For Dual-tone multi-frequency signalling (DTMF)
f1=697/8000;
f2=1209/8000;
fs=8000;
n=1:205;
x1=sin(2*pi*f1*n);
x2=sin(2*pi*f2*n);
x=x1+x2;
y=fft(x,205);
k=1:50;
zk=y(k);
stem(abs(zk));
Program for Design of Filter using Keiser Window
m=input('\ enter the value of m=30')
>> beta=input('\ enter the value of Beta=12')
>> wc=input('\ enter wc=0.3')
>> wn=kaiser(m,beta);
>> hn=fir1(m-1,wc,wn);
freqz(hn,1,512);
Program for Bandpass Butterworth Filter
ap=2
as=30
ws=[0.2*pi,0.4*pi]
wp=[0.1*pi,0.5*pi]
[n,wn]=buttord(wp/pi,ws/pi,ap,as)
[b,a]=butter(n,wn,'bandpass')
w=0:0.01:pi
[h,wd]=freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of Bandpass butterworth filter')
Program for Bandstop Butterworth Filter
ap=2
as=30
ws=[0.2*pi,0.4*pi]
wp=[0.1*pi,0.5*pi]
[n,wn]=buttord(wp/pi,ws/pi,ap,as)
[b,a]=butter(n,wn,'stop')

w=0:0.01:pi
[h,wd]= freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of Bandstop butterworth filter')
Program for High Pass Butterworth Filter
ap=2;
as=30;
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=buttord(wp,ws,ap,as)
[b,a]=butter(n,wn,'high')
w=0:0.1:pi
[h,wd]= freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of low pass butterworth filter')
Program for Low Pass Butterworth Filter
ap=2;
as=30;
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=buttord(wp,ws,ap,as)
[b,a]=butter(n,wn)
w=0:0.1:pi
[h,wd]= freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of low pass butterworth filter')
Program for Bandpass Chebyshev Filter
ap=2
as=20
ws=[0.2*pi,0.4*pi]
wp=[0.1*pi,0.5*pi]
[n,wn]= cheb1ord(wp/pi,ws/pi,ap,as)
[b,a]= cheby1(n,ap,wn,'bandpass')
w=0:0.01:pi
[h,wd]=freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of Bandpass Chebyshev filter')
Program for Bandstop Chebyshev Filter
ap=2
as=20
ws=[0.2*pi,0.4*pi]
wp=[0.1*pi,0.5*pi]
[n,wn]= cheb1ord(wp/pi,ws/pi,ap,as)
[b,a]= cheby1(n,ap,wn,'stop')
w=0:0.01:pi
[h,wd]=freqz(b,a,w)
m=20*log10(abs(h))

plot(wd/pi,m)
title('\bf output of Bandstop Chebyshev filter')
Program for Highpass Chebyshev Filter
ap=2
as=20
ws=[0.2*pi]
wp=[0.3*pi]
[n,wn]= cheb1ord(wp/pi,ws/pi,ap,as)
[b,a]= cheby1(n,ap,wn,'high')
w=0:0.01:pi
[h,wd]=freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of Highpass Chebyshev filter')

Program for Lowpass Chebyshev Filter


ap=1
as=15
ws=[0.2*pi]
wp=[0.3*pi]
[n,wn]= cheb1ord(wp/pi,ws/pi,ap,as)
[b,a]= cheby1(n,ap,wn)
w=0:0.01:pi
[h,wd]=freqz(b,a,w)
m=20*log10(abs(h))
plot(wd/pi,m)
title('\bf output of Lowpass Chebyshev filter')

S-ar putea să vă placă și