42
LAB MANNUAL DIGITAL SIGNAL PROCESSING (EC-603) Submit By Name-………………….. Roll no-…………………… Session -…………………. Submit to Prof. ……………… Prof. Prateek Mishra Asst. professor HOD EC Dept. GNCSGI EC Dept. GNCSGI Digital Signal Processing Lab GNCSGI Jabalpur Page 1

Digital Signal Processing Lab manual using matlab

Embed Size (px)

DESCRIPTION

Matlab programmes related to Signal manipulations systems and filter design

Citation preview

Page 1: Digital Signal Processing Lab manual using matlab

LAB MANNUALDIGITAL SIGNAL PROCESSING (EC-603)

Submit By

Name-…………………..

Roll no-……………………

Session -………………….

Submit to

Prof. ……………… Prof. Prateek Mishra

Asst. professor HOD

EC Dept. GNCSGI EC Dept. GNCSGI

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING, GNCSGI

GLOBAL NATURE CARE SANGATHANS GROUP

Digital Signal Processing Lab GNCSGI Jabalpur Page 1

Page 2: Digital Signal Processing Lab manual using matlab

OF INSTITUTION, JABALAPUR

Digital signal processing (EC- 603)

List of Experiments

1. To plot and demonstrate various types of discrete time signals.2. To plot and demonstrate shifting of discrete time signals.3. To plot and demonstrate addition, subtraction multiplication of

discrete time signals.4. To find the impulse response of a discrete time system described

by difference equation and also find its stability.5. Implement an M-Point moving average filter.6. Implementation of an integrator and differentiator.7. To Sketch Pole zero plot of a given transfer function.8. Finding the Discrete time Fourier Transform of a given impulse

response and verify its convolution property.9. To verifying the convolution property of DTFT.

10. To implement FIR Low Pass Filter Using Windowing11. To implement FIR High Pass Filter Using Windowing

EC – 603 Digital Signal Processing

Digital Signal Processing Lab GNCSGI Jabalpur Page 2

Page 3: Digital Signal Processing Lab manual using matlab

Unit – IDiscrete-Time Signals and Systems Discrete-time signals, discrete- time systems, analysis of discrete-time linear time-invariant systems, discrete time systems described by difference equation, solution of difference equation, implementation of discrete-time systems, stability and causality, frequency domain representation of discrete time signals and systems. Unit - IIThe z-Transform The direct z-transform, properties of the transform, rational z-transforms, inversion of the z transform, analysis of linear time-invariant systems in the z- domain, block diagrams and signal flow graph representation of digital network, matrix representation. Unit - IIIFrequency Analysis of Discrete Time Signals Discrete fourie series (DFS), properties of the DFS, discrete Fourier transforms (DFT) properties of DFT, two dimensional DFT, circular convolution. Unit - IVEfficient Computation of the DFT- FFT algorithms, decimation in time algorithm, decimation in frequency algorithm, decomposition for ‘N’ composite number. Unit - VDigital filters Design Techniques Design of IIR and FIR digital filters, Impulse invariant and bilinear transformation, windowing techniques- rectangular and other windows, examples of FIR filters, design using windowing.

Experiment detail

Digital Signal Processing Lab GNCSGI Jabalpur Page 3

Page 4: Digital Signal Processing Lab manual using matlab

S no. Object Pg no

1To plot and demonstrate various types of discrete time

signals.

2To plot and demonstrate shifting of discrete time signals.

3To plot and demonstrate addition, subtraction

multiplication of discrete time signals.

4To find the impulse response of a discrete time system

described by difference equation and also find its stability.

5Implement an M-Point moving average filter.

6Implementation of an integrator and differentiator.

7To Sketch Pole zero plot of a given transfer function.

8Finding the Discrete time Fourier Transform of a given impulse response and verify its convolution property.

9 To verifying the convolution property of DTFT.

10 To implement FIR Low Pass Filter Using Windowing

11 To implement FIR High Pass Filter Using Windowing

1. Demonstration of basic discrete time signals. Aim:- To plot and demonstrate various types of discrete time signals.Digital Signal Processing Lab GNCSGI Jabalpur Page 4

Page 5: Digital Signal Processing Lab manual using matlab

Equipments:-Operating System – Windows XP or above versionConstructor – script or SimulatorSoftware - MATLAB 7 or above version

Theory:- We use several elementary sequences in digital signal processing for analysis purposes. Their definitions and MATLAB representations are given below.

1. Unit sample sequence:-

δ(n) = {1, n=00 , n≠ 0 = {…..,0,0,0,1,0,0,0,…..

In MATLAB t he function zeros (1, N) generates a row vector of N zeros, which can be used to implement δ(n) over a finite interval. However, the implementing δ (n) can be done by taking n=0 sample equal to 1.

Program:-

% Digital Signal Processing Lab% Program to generate a unit impulse signalN=64;n=-(N/2): ((N/2)-1);x=zeros(1,N);x((N/2)+1)=1;stem(n,x);grid;title('A unit impulse signal ');xlabel('Sampel Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 5

Page 6: Digital Signal Processing Lab manual using matlab

2. Unit step sequence:-

u(n) = {1, n≥ 00 , n<0

In MATLAB t he function ones (1, N) generates a row vector of N ones. It can be used to generate u(n) over a finite interval.

Program:-% Digital Signal Processing Lab% Program to generate a unit step signaln=-20:20;u=[zeros(1,20),ones(1,21)];stem(n,u);grid;title('A unit step signal ');xlabel('Sampel Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 6

Page 7: Digital Signal Processing Lab manual using matlab

3. Real-valued exponential sequence:-

x(n) = (α)n , ∀n ,α∈R

In MATLAB an array operator " . ^ " is required to implement a real exponential sequence. For example, to generate z(n) = (0.9)n , 0 < n < 10, we will need the following MATLAB script:>> n=0:10; x=(0.9).^n;

Program:-

% Digital Signal Processing Lab% Program to generate a real valued exponential signal% x(n)=(0.9).^nn=0:40;x=(0.9).^n;stem(n,x);grid;title('A Real valued Exponential signal ');xlabel('Sampel Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 7

Page 8: Digital Signal Processing Lab manual using matlab

4. Sinusoidal sequence:-

x(n) = cos (ωo n + θ) ∀n where ωo = 2π/N where N is period of this discrete time sinusoid. Where θ is the phase in radians, a MATLAB function cos (or sin) is used to generate sinusoidal sequences.

Program:-

% Digital Signal Processing Lab% Program to generate a sinusoidal signal% x(n)=A*cos((2*pi/N)+ theta)in this example N=12 and theta is pi/3 n=0:40;x=2*cos((2*(pi/12)*n)+pi/3);stem(n,x);grid;title('A sinusoidal signal of period N=12');xlabel('Sample Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 8

Page 9: Digital Signal Processing Lab manual using matlab

2. Demonstration of shifting of discrete time signals.

Aim:- To plot and demonstrate shifting of discrete time signals.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory:- Shifting is any discrete time sequence can be seen as delaying or advancing the sequence in time or sample interval if x(n) is a discrete time signal than its delayed version can be expressed as x(n- no) where no is amount of shift. To implement this using MATLAB we have to pad no numbers of zeros before starting the sequence x(n).

Digital Signal Processing Lab GNCSGI Jabalpur Page 9

Page 10: Digital Signal Processing Lab manual using matlab

Program:-

% Digital Signal Processing Lab% Program to generate a sinusoidal signal and delay it by 10 samples% x(n)=A*cos((2*pi/N)+ theta)in this example N=12 and theta is 0 and % amount of delay is of 20 samplesN=64n=0:N-1;x=2*cos(2*(pi/12)*n);xd =[zeros(1,20), x(1:(N-20))];subplot(2,1,1);stem(n,x);grid;title('A sinusoidal signal of period N=12');xlabel('Sample Number');ylabel('Amplitude');subplot(2,1,2);stem(n,xd);grid;title('A delayed sinusoidal signal of period N=12 amount of delay =20');xlabel('Sample Number');ylabel('Amplitude');% in this section we will generate a delayed unit impulse sequence % delayed by 20 samplesm=-(N/2): ((N/2)-1);u=zeros(1,N);u((N/2)+1)=1;ud=[zeros(1,20),u(1:N-20)];figure(2)subplot(1,2,1)stem(m,u);grid;title('A unit impulse signal ');xlabel('Sample Number');ylabel('Amplitude');subplot(1,2,2)stem(m,ud);grid;title('A unit impulse signal delayed by 20 samples');xlabel('Sample Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 10

Page 11: Digital Signal Processing Lab manual using matlab

3. Demonstration basic manipulation on discrete time signals.

Aim:- To plot and demonstrate addition, subtraction multiplication of discrete time signals.

Equipments:-Operating System – Windows XP

Digital Signal Processing Lab GNCSGI Jabalpur Page 11

Page 12: Digital Signal Processing Lab manual using matlab

Constructor - SimulatorSoftware - MATLAB 7

Theory:-

1. Signal addition: - This is a sample -by-sample addition given by x1(n) + x2(n) it is implemented in MATLAB by the arithmetic operator “+”. However, the lengths of x1(n) and x2(n) must be the same.

2. Signal subtraction:- This is a sample -by-sample subtraction given by x1(n) - x2(n) It is implemented in MATLAB by the arithmetic operator “-”. However, the lengths of x1(n) and x2(n) must be the same.

3. Signal subtraction:- This is a sample -by-sample multiplication given by x1(n) *x2(n) It is implemented in MATLAB by the arithmetic operator “*”. However, the lengths of x1(n) and x2(n) must be the same. This operation is non linear operation whereas addition and subtraction are linear operations.

Program :-

% Digital Signal Processing Lab% Program to demonstrate addition subtraction and multiplication % of two different sinusoids having periods N1=15 and N2=30n=0:50;x1=cos(2*pi/15*n);x2=0.5*sin(2*pi/30*n);add=x1+x2;sub=x1-x2;mul=x1 .* x2;subplot(1,2,1);stem(n,x1);grid;title('A sinusoidal signal of N=15');xlabel('Sample Number');ylabel('Amplitude');subplot(1,2,2);stem(n,x2);grid;title('A sinusoidal signal of N = 30');xlabel('Sample Number');ylabel('Amplitude');figure(2);subplot(1,3,1);stem(n,add);grid;title('A addition x1+x2');xlabel('Sample Number');

Digital Signal Processing Lab GNCSGI Jabalpur Page 12

Page 13: Digital Signal Processing Lab manual using matlab

ylabel('Amplitude');subplot(1,3,2);stem(n,sub);grid;title('A subtraction x1-x2');xlabel('Sample Number');ylabel('Amplitude');subplot(1,3,3);stem(n,mul);grid;title('A multiplication x1*x2');xlabel('Sample Number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 13

Page 14: Digital Signal Processing Lab manual using matlab

Digital Signal Processing Lab GNCSGI Jabalpur Page 14

Page 15: Digital Signal Processing Lab manual using matlab

4. Finding impulse response of a given discrete time system and finding it’s stability.

Aim:- To find the impulse response of a discrete time system described by difference equation and also find it’s stability.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory:- Impulse response of a given system described by a difference equation can be found by using MATLAB function impz(num,den,N) where num is a row vector of coefficient of input x(n) = δ(n) and it’s delayed forms, similarly den is a row vector of coefficients of out put y(n) and it’s delayed forms. And N is total number of samples for which we have to find response.

Where as the test of stability of a system can be performed using the method “Sum of Absolute Test” in this method after finding impulse response of a system for N samples we test the absolute value of h(n) i.e. impulse response, if the absolute value is decreasing as N is increasing and if the absolute value of h(n) becomes < 10-6

the system can be considered as stable system.

Program:-% Digital Signal Processing Lab% Program to find impulse response of a system% y(n)+ 1.5 y(n-1)+ 0.9 y(n-2)= x(n)- 0.8 x(n-1)clc;N=200;n=0:N;num = [1 -0.8];den = [1 1.5 0.9];h = impz(num,den,N+1);stem(n,h);xlabel('Time index n');ylabel('Amplitude');title('Impulse Response h(n)');sum = 0;for K=1:N+1; sum = sum + abs(h(K)); if abs(h(K))< 10^-6; break endendstem(n,h);

Digital Signal Processing Lab GNCSGI Jabalpur Page 15

Page 16: Digital Signal Processing Lab manual using matlab

xlabel('Time index n');ylabel('Amplitude');title('Impulse Response h(n)');grid;disp('value = ');disp(abs(h(K)));disp('sum of h(n) from n = 0 to N = ')disp(sum);

Out Put:- value = 1.6761e-0.05

sum of h(n) from n = 0 to N = 35.3591

Digital Signal Processing Lab GNCSGI Jabalpur Page 16

Page 17: Digital Signal Processing Lab manual using matlab

5. M-Point Moving Average Filter

Aim:- Implement an M-Point moving average filter.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory: - an M pint moving average filter can be described as below.

y (n )=1 /M∑k=0

M

x (n−k )

This can be implemented using MATLAB function “filter” and the matlab script to implement this can be written as: >> y=filter(num,1,x);Where x(n) is input and num is a row vector of all the elements 1 and it is a 1xM matrix, and 1 is denominator co efficient.

Program:-% Digital Signal Processing Lab% Program to impliment M point moving average filter% y(n)= 1/M(x(n)+ x(n-1)+x(n-2)+ x(n-3)+x(n-4)+ ......+x(n-M))close all;clear all;clc;clf;n= 0:56;s1=cos(2*pi*0.05*n);s2=cos(2*pi*0.5*n);s=s1+s2;subplot(2,2,1);plot(n,s1);grid;title('Orignal signal s1 ,N=20 ');xlabel('number of sampel');ylabel('Amplitude');subplot(2,2,2);plot(n,s2);grid;title('Additive Noise signal s2 ,N=2 ');xlabel('number of sampel');ylabel('Amplitude');subplot(2,2,3);plot(n,s);grid;

Digital Signal Processing Lab GNCSGI Jabalpur Page 17

Page 18: Digital Signal Processing Lab manual using matlab

title('Noisy signal to be filtered = s1+s2 ');xlabel('number of sampel');ylabel('Amplitude');M=input('Please enter the length of filter = ');num=ones(1,M);y=filter(num,1,s)/M;subplot(2,2,4);plot(n,y);grid;title(' Filtered signal ');xlabel('number of sampel');ylabel('Amplitude');

Please enter the length of filter = 10

Digital Signal Processing Lab GNCSGI Jabalpur Page 18

Page 19: Digital Signal Processing Lab manual using matlab

6. Implementation of integrator and differentiator

Aim:- implementation of an integrator and differentiator.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory: - In digital signal processing a differentiator and integrator can be synthesized using difference equations,

1. Differentiator:- a differentiator can be implemented using finding the first difference of any given input signal x(n) and it is given as:y(n) = x(n)-x(n-1) this is called the first difference of input x(n).

2. Integrator or Accumulator:- An integrator can be viewed as :

y(n)= ∑k=−∞

n

x (k ) and this can be converted in to difference equation as: simulation of Integration Using Trapezoidal rule y(n)=y(n-1)+1/2(x(n)+x(n-1))

Program:-% Digital Signal Processing Lab% Program to find integration and differentiation of a given signal x(n)% the integrator can be implemented using y(n)- y(n-1)= x(n)% and differentiation can be implemented using y(n)= x(n)- x(n-1)% in this program we will use x(n)= u(n)i.e. unit step signaln=-50:50;u=[zeros(1,50) ones(1,51)];axis([-50,50,0,1]);subplot(3,1,1);stem(n,u);grid;title('imput unit step signal');xlabel('sampel number');ylabel('Amplitude');% implementing differentiation y(n)= x(n)- x(n-1)num1=[1,-1];den1=[1];yd=filter(num1,den1,u);subplot(3,1,2);stem(n,yd);grid;title('Differentiation of unit step signal is impulse signal');xlabel('sampel number');ylabel('Amplitude');% implementing integration y(n)- y(n-1)= ½ x(n)+ ½ x(n-1)

Digital Signal Processing Lab GNCSGI Jabalpur Page 19

Page 20: Digital Signal Processing Lab manual using matlab

num2=[1/2,1/2];den2=[1 ,-1];yi=filter(num2,den2,u);subplot(3,1,3);stem(n,yi);grid;title('Integration of unit step signal is unit ramp signal');xlabel('sampel number');ylabel('Amplitude');

Digital Signal Processing Lab GNCSGI Jabalpur Page 20

Page 21: Digital Signal Processing Lab manual using matlab

7. Z transform and pole zero plot

Aim:- Sketching Pole zero plot of a given transfer function.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory:- Assume we have a transfer function in the z-domain given by:-

X ( z )= z−1

1−0 .25 z−1−0 .375 z−2=z

z2−0 .25 z−0 .375

Factoring this, it’s partial fraction expansion can be found to be:-

X ( z )= z( z−0 . 75 ) ( z+0 . 5 )

=c1 z

(z−0 .75 )+

c2 z( z+0. 5 )

= 0. 8 z( z−0 .75 )

+ −0.8 z( z+0 .5 )

The inverse z-transform of this is thus:-

x (n )=[ (0 .8 ) (0 .75 )n+(−0 .8 ) (−0 .5 )n ]u (n )

There are several MATLAB functions that could assist with calculating and analyzing these results. We can find the roots of the denominator polynomial using,

den = [1 -0.25 -0.375]; roots(den)

We can then plot the zeros and poles either with

1. Zeros and poles in column vectors

zplane(z,p) z = [0] p = [0.75; -0.5]

2. numerator and denominator coefficients in row vectors

num = [0 1 0] den = [1 -0.25 -0.375]

zplane(num,den)

Digital Signal Processing Lab GNCSGI Jabalpur Page 21

Page 22: Digital Signal Processing Lab manual using matlab

Program:-

% Digital Signal Processing Lab% Program to show pole zero location in complex z plane% for a given transfer function,Described in theory clc;close all;clear all;num=[0];den=[1,-0.25,-0.375];z=roots(num);p=roots(den);% Pole zero plot using Zeros and poles in column vectorszplane(z,p);title('Pole zero plot using Zeros and poles in column vectors');figure(2);%Pole zero plot using numerator and denominator coefficients in row vectorszplane(num,den);title('Pole zero plot using numerator and denominator coefficients in row vectors');

Digital Signal Processing Lab GNCSGI Jabalpur Page 22

Page 23: Digital Signal Processing Lab manual using matlab

Digital Signal Processing Lab GNCSGI Jabalpur Page 23

Page 24: Digital Signal Processing Lab manual using matlab

8. Discrete time Fourier Transform and it’s Convolution property

Aim: - Finding the Discrete time Fourier Transform of a given impulse response and verify it’s convolution property.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory:- As we know that DTFT of a discrete time signal is continuous and periodic in nature having period 2п . In matlab using function freqz we can compute H(eiω) i.e. the Fourier transform of any given system described by difference equation , and we can plot it’s real value and imaginary value and with respect to frequency in radian and we can also plot the magnitude spectrum and phase spectrum of that system.

Program:-

% Digital signal processing Lab% Program to find DTFT of a given system described by difference equation% y(n)- 0.6 y(n-1)= 2 x(n)+ x(n-1)close all;clear all;clc;clf;% computing the frequency samples of the DTFTw=-4*pi:8*pi/511:4*pi;num=[2 1]; den=[1 -0.6];H=freqz(num,den,w);% plot the DTFTsubplot(2,1,1);plot(w/pi, real(H)); grid;title('Real part of H(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Amplitude');subplot(2,1,2);

Digital Signal Processing Lab GNCSGI Jabalpur Page 24

Page 25: Digital Signal Processing Lab manual using matlab

plot(w/pi, imag(H)); grid;title('Imaginary part of H(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Amplitude');figure(2);subplot(2,1,1);plot(w/pi, abs(H)); grid;title('Magnitude Spectrum of H(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Amplitude');subplot(2,1,2);plot(w/pi, angle(H)); grid;title('Phase Spectrum of H(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Phase in Radians');

Out Put:-

Digital Signal Processing Lab GNCSGI Jabalpur Page 25

Page 26: Digital Signal Processing Lab manual using matlab

Digital Signal Processing Lab GNCSGI Jabalpur Page 26

Page 27: Digital Signal Processing Lab manual using matlab

9. convolution property of DTFT.Aim: - verifying the convolution property of DTFT.

Equipments:-Operating System – Windows XPConstructor - SimulatorSoftware - MATLAB 7

Theory:- As we know that if two sequences are convolved in time domain than their frequency responses i.e. DTFT multiplies in frequency domain to demonstrate this property we first convolve two sequences and will find Fourier transform of convolution, on the other side we separately find the discrete time Fourier transform of two sequences and then multiply both of them to prove the convolution property of DTFT.Basic Matlab function used will be the same i.e. “freqz”.

Program:-

% Digital signal processing Lab% Demonstration of convolution property of DTFT% x1 = [1 3 5 7 9 11 13 15 17]% x2 = [1 -2 3 -2 1]close all;clear all;clc;clf;w= -pi:2*pi/255:pi;x1 = [1 3 5 7 9 11 13 15 17];x2 = [1 -2 3 -2 1];y = conv(x1,x2);H1 = freqz(x1,1,w);H2 = freqz(x2,1,w);Hp = H1.*H2;H3 = freqz(y,1,w);subplot(2,2,1);plot(w/pi,abs(Hp));grid;title('Magnitude spectrum of convolved sequence Hp(e^{j\omega})');

Digital Signal Processing Lab GNCSGI Jabalpur Page 27

Page 28: Digital Signal Processing Lab manual using matlab

xlabel('\omega/\Pi');ylabel('Amplitude');subplot(2,2,2);plot(w/pi,abs(H3));grid;title('Product of magnitude spectrum H3(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Amplitude');subplot(2,2,3);plot(w/pi,angle(Hp));grid;title('Phase spectrum of convolved sequence Hp(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Angle in Radian');subplot(2,2,4);plot(w/pi,angle(H3));grid;title('Phase spectrum of Product of Phase spectrum H3(e^{j\omega})');xlabel('\omega/\Pi');ylabel('Angle in Radian');

Out Put:-

Digital Signal Processing Lab GNCSGI Jabalpur Page 28

Page 29: Digital Signal Processing Lab manual using matlab

|H(ejω)|

0

ω

π-π

10. Designing of Fir Low Pass Filter Aim:- To implement FIR Low Pass Filter Using WindowingEquipments:-Operating System – Windows XP or above versionConstructor – script or SimulatorSoftware - MATLAB 7 or above version

Theory:-Desired magnitude response of the ideal filter is given by the equation

H d ( e jω)=e− jωτ when∨ω∨≤ ωc

H d ( e jω)=0when ωc ≤∨ω∨≤ π

Where τ is shift τ=(N-1)/2 where N= length of window (odd)

And ωc = cut off frequency of LPF

Figure 1 Frequency response of FIR low pass filter with cutoff frequency ωc

Corresponding impulse response of LPF will be:

h (n )=sin [ωc (n−τ )]

π (n−τ )wheren=0¿ N−1

¿h (n )=ωc

πfor n=τ

Digital Signal Processing Lab GNCSGI Jabalpur Page 29

Page 30: Digital Signal Processing Lab manual using matlab

Where N is length of window having odd length

Program:-clc;clf;close all;clear all;clc;% designing of LPF using Hamming window% take cut off frequency wp as input % h(n)= sin[wp(n-t)]/pi*(n-t) when n != t% h(n)= wp/pi when n=tf=input('Give cutoff frequency in hertz between 0 to 4kHZ ');wp=pi*f/4000;N = 1025;t=(N-1)/2;n=0:N-1;h1=sin(wp*(n-t));h2=(pi*(n-t));h1((n-t)==0)=wp;h2((n-t)==0)=pi;h=h1./h2;stem(n,h);title('impulse response of filter');xlabel('sampel number');ylabel('Amplitude');w = 0.54-0.46*(cos(2*pi*n/(N-1)));figure(2);stem(n,w);title('Hamming window');xlabel('sampel number');ylabel('Amplitude');y=h.*w;figure(3);stem(n,y);title('impulse response of filter h(n)*w(n)');xlabel('sampel number');ylabel('Amplitude');z=fftshift(abs(fft(y)));f=-4000:(8000/1024):4000;figure(4)plot(f,z);xlabel('frequency in hertz');ylabel('Amplitude Spectrum');title('Amplitude spectrum of FIR LPF');

Digital Signal Processing Lab GNCSGI Jabalpur Page 30

Page 31: Digital Signal Processing Lab manual using matlab

Out Put:-

Aim:- To implement FIR High Pass Filter Using WindowingEquipments:-Operating System – Windows XP or above version

Digital Signal Processing Lab GNCSGI Jabalpur Page 31

Page 32: Digital Signal Processing Lab manual using matlab

-π π0

Constructor – script or SimulatorSoftware - MATLAB 7 or above version

Theory:-Desired magnitude response of the ideal filter is given by the equation

H d ( e jω)=e− jωτ when ωc ≤∨ω∨≤ π

H d ( e jω)=0when 0≤|ω|<ωc

Where τ is shift τ=(N-1)/2 where N= length of window

And ωc = cut off frequency of HPF

Corresponding impulse response of LPF will be:

h (n )=−sin [ωc(n−τ)]

π (n−τ )where n=0¿ N−1

¿h (n )=π−ωc

πfor n=τ

Where N is length of window having odd length

Program:-clc;clf;close all;

Digital Signal Processing Lab GNCSGI Jabalpur Page 32

Page 33: Digital Signal Processing Lab manual using matlab

clear all;clc;% designing of HPF using Hamming window% take cut off frequency wp as input % h(n)= -sin[wc(n-t)]/pi*(n-t) when n != t% h(n)= pi-wc/pi when n=tf=input('Give cutoff frequency in hertz between 0 to 4kHZ ');wc=pi*f/4000;N = 1025;t=(N-1)/2;n=0:N-1;h1=-sin(wc*(n-t));h2=(pi*(n-t));h1((n-t)==0)=pi-wc;h2((n-t)==0)=pi;h=h1./h2;stem(n,h);title('impulse response of filter');xlabel('sampel number');ylabel('Amplitude');w = 0.54-0.46*(cos(2*pi*n/(N-1)));figure(2);stem(n,w);title('Hamming window');xlabel('sampel number');ylabel('Amplitude');y=h.*w;figure(3);stem(n,y);title('impulse response of filter h(n)*w(n)');xlabel('sampel number');ylabel('Amplitude');z=fftshift(abs(fft(y)));f=-4000:(8000/1024):4000;figure(4)plot(f,z);xlabel('frequency in hertz');ylabel('Amplitude Spectrum');title('Amplitude spectrum of FIR HPF');

Results:

Digital Signal Processing Lab GNCSGI Jabalpur Page 33

Page 34: Digital Signal Processing Lab manual using matlab

Digital Signal Processing Lab GNCSGI Jabalpur Page 34