Professional Documents
Culture Documents
h = impz (b,a,w): It computes N samples of the impulse response of the filter describe b and
a.
y = fft (x): It computes the FFT of the vector and stores it in vector y.
y = fft (x,N): It computes N-point FFT of the vector x by padding the sequence x with zeros if
the sequence length is less than the N-point truncated if it has more and stores it in vector y.
ifft (x): It computes the IFFT of the vector x.
ifft (x,N): It computes N-point IFFT of the vector x.
zplane (z,p): Plot the poles and zeros supplied by the column vector z and p.
zplane (num,den): plots the poles and zeros of the transfer function represented by the rows
in num and dem.
h = impz (num,den,n): It computes the impulse response of the digital filter transfer function
represented by num and dem.
[n,wn] = buttord (wp,ws,rp,rs): Find the lowest order N of digital butterworth filter that
loses no more than rp db in pass band and has atleast rs db of attenuation in stop band, wp
and ws are the passband and stopband edge frequencies normalized from 0 to 1.
[b,a] = butter (n,wn,high): Design an Nth order high pass digital butterworth filter.
[n,wn] = cheb1ord (wp,ws,rp,rs): Finds the lowest order n of the digital chebyshev type I
filter that loses no more than rp db in pass band and has atleast rs db of attenuation in stop
band wp and ws are the passband and stopband edge frequencies mormalised from 0 to 1.
[n,wn] = cheb2ord (wp,ws,rp,rs): Finds the lowest order n of the digital chebyshev type II
filter that loses no more than rp db in pass band and has atleast rs db of attenuation in stop
band wp and ws are the passband and stopband edge frequencies mormalised from 0 to 1.
[b,a] = cheby2 (n,r,wn): Design an nth order low pass digital chebyshev filter with the stop
band ripple r describe down and stop band edge frequency wn.
[b,a] = cheby2 (n,rs,wn,high): Design an Nth order high pass digital chebyshev filter
[b,a] = cheby2 (n,r,wn,stop): Design an nth order band stop digital chebyshev filter if
wn=[w1 w2].
[b,a] = cheby1 (n,r,Wn): Design an nth order low pass digital chebyshev type I filter with r
db of ripples in the stopband and r db of ripple ine pass band, cheby1 returns the filter co-
efficient n+1 vector with b (num) and a (den).
[b,a] = cheby1 (n,r,wn,high): Design an nth order high pass digital chebyshev type I filter.
[numd,dend] = bilinear(num,den,fs): Converts the s domain transfer function specified by
num and den containing numerator and denominator transfer function coefficient into z domain
transfer function are store in the vetor numd, dend.
W = boxcar (N): Return the N point rectangular window.
W = Bartlett (N): Return the N point bartlett triangular window.
W = hamming (N): Return N point, symmetric hamming window in coluwn vector.
hann (N): Return N point window symmetric hamming window in coluwn vector.
hanning (N): Return N point symmetric hamming window in coluwn vector. In this case the
first and cast zero-weighted window samples are not included.
blackman (N): Return N point symmetric blackman window in coluwn vector.
B = fir1 (N,Wn): Design a N order low pass FIR digital filter and return the filter, the filter
coefficient in length N+1 vector B. The cut-off freq Wn must be between 0 <Wn<10, with 1.0
corresponds to half the sample rate.
B = fir1(N,Wn,high): Design a N order FIR digital high pass filter
B = fir1 (N,Wn,stop): It is a bandstop filter if wn=[w,wn].
y = decimate (x,m): It resamples the sequence in the vector x at m times the original
sampling rate.
Expt 1. WAVEFORM GENERATION
Amplitude
1
5
0 0
0 2 4 6 8 Time
10 0 2 4 6 8 10
Time
Sine Wave Cosine Wave
1 1
Amplitude
Amplitude
0 0
-1 -1
0 2 4 6 8 10 0 2 4 6 8 Time
10
Time
Square Wave Sawtooth Wave
1 1
Amplitude
Amplitude
0 0
-1 -1
0 2 4 6 8 10 0 2 4 6 8 10
Time Time
Amplitude
10
0.5
5
0 0
0 5 10 15 0 5 10 15
Time Time
Sinosoidal Sequence Cosine Sequence
1 1
Amplitude
Amplitude
0 0
-1 -1
0 5 10 15 0 5 10 15
Time Time
Exponential Sequence Unit Impulse
20 1
Amplitude
Amplitude
10 0.5
0 0
0 5 10 15 -4 -2 0 2 4
Time Time
Expt 2 : LINEAR CONVOLUTION AND CIRCULAR CONVOLUTION
%impulse seq.
h=input('Enter the impulse sequence h(n)= ');
N2=length(h);
n1=0:1:N2-1;
subplot(3,1,2); stem(n1,h,'k');
xlabel('n--->'); ylabel('Amplitude'); title('impulse sequence h(n)');
%Output conv.
y=conv(x,h)
N=N1+N2-1;
n2=0:1:N-1;
subplot(3,1,3); stem(n2,y,'k');
xlabel('Time'); ylabel('Amplitude'); title('Linear Convolution of two sequence');
0
0 0.5 1 1.5 2 2.5 3
n----->
impulse sequence h(n)
4
Amplitude
0
0 0.5 1 1.5 2 n---> 2.5 3
Linear Convolution of two sequence
20
Amplitude
10
0
0 1 2 3 4 5 6
Time
CIRCULAR CONVOLUTION
0
0 0.5 1 1.5 2 n---> 2.5 3
x2(n) Input Sequence 2
4
Amplitude
0
0 0.5 1 1.5 2 n---> 2.5 3
Convolution of x1(n)&x2(n) Response
20
Amplitude
10
0
1 1.5 2 2.5 3 3.5 4
n--->
0.6 3
Amplitude
0.4
0.2 2
Amplitude
-0.2 1
-0.4
-0.6 0
-0.8 0 0.02 0.04 0.06 0.08 0.1
Time
-1
0 0.02 0.04 0.06 0.08 0.1 -16
Time
x 10 Reconstructed undersampled fs<<2fm signal
4
3
Amplitude
0
0 0.02 0.04 0.06 0.08 0.1
Time
-16 Sampled at Nyquist rate fs=2fm signal Oversampled fs>>2fm signal
x 10 1
8
6 0.5
Amplitude
Amplitude
4 0
2 -0.5
-1
0 0 0.02 0.04 0.06 Time 0.08 0.1
0 0.02 0.04 0.06 Time 0.08 0.1
Reconstructed oversampled fs>>2fm signal
-16 Reconstructed Nyquist rate fs=2fm signal
x 10 1
8
0.5
6
Amplitude
0
Amplitude
4
-0.5
2
-1
0 0 0.02 0.04 0.06 0.08 0.1
0 0.02 0.04 0.06 0.08 0.1 Time
Time
6 30
Amplitude
Amplitude
4 20
2 10
0 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
N---> k--->
2 6
Amplitude
Angle
0 4
-2 2
-4 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
k---> n--->
Amplitude
5
0
0 1 2 3 4 5 6 7
n----->
DFT
40
Amplitude
20
0
0 1 2 3 4 5 6 7
k------->
IDFT
10
Amplitude
0
0 1 2 3 4 k------> 5 6 7
0
Gain in deciBel
-100
-200
-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency in rad/sec
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency in rad/sec
Magnitude Plot (BSF)
50
Gain in deciBel
-50
-100
-150
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency in rad/sec
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency in rad/sec
% Chebyshev filters
clear all; clc; close all;
rp=input('Enter the pass band ripple:');
rs=input('Enter the stop band ripple:');
fp=input('Enter the pass band frequency:');
fs=input('Enter the stop band frequency:');
fsamp=input('Enter the sampling frequency:');
wp=2*fp/fsamp; ws=2*ws/fsamp;
%LOW PASS FILTER
[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h)); an=angle(h);
disp('Filter order'); disp(n); disp('Cut-off frequency'); disp(wn);
subplot(2,1,1); plot(om/pi,m);
ylabel('Gain in db--->'); xlabel('(a)Normalized frequency--->');
title('Low pass filter');
subplot(2,1,2); plot(om/pi,an);
xlabel('(b)Normalized frequency--->'); ylabel('Phase in radians--->');
-10
Gain in db--->
-20
-30
-40
-50
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a)Normalized frequency--->
0
Phase in radians--->
-0.5
-1
-1.5
-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b)Normalized frequency--->
Bandstop filter
0
-5
Gain in db--->
-10
-15
-20
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a)Normalized frequency--->
1.5
1
Phase in radians--->
0.5
-0.5
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b)Normalized frequency--->