Vous êtes sur la page 1sur 8

Assignment No.

1 Design of FIR Digital Filters Subject: Digital Signal Processing

Prepared by: Abdul Sattar Malokani Roll No. ME CIE 24

Submitted to: Professor Dr. Mukhtiar Ali Unar Institute of Information Technology Mehran University of Engineering and Technology, Jamshoro.

Dated: 4/4/12
Page 1

%Assignment No.1 Design of FIR Filters %Part A. Filter Design Parameters: %Low Pass %Cut off Frequency = 5000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 11 %Design Method Windowing i.e. Rectangular Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 11; % Order of the Filter Fc = 5000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Rect_Win = boxcar(N); % Rectangular Windows Coefficients disp('Windows Coefficient'); disp(Rect_Win) Hn = fir1(N-1,Fc,Rect_Win); % Windowed Filter Coefficients disp('Windowed Filter Coefficient'); disp(Hn) [H,f] = freqz(Hn,1,1024,Fs); %Impulse frequency response Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency (Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency') ylabel ('Phase (radian)')

Magnitude Response 0

Gain (dB)

-50

-100

0.5

1 1.5 Frequency (Hz) Phase Response

2.5 x 10
4

Phase (radian)

-2

-4

-6

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 2

%Assignment No.1 Design of FIR Filters %Part B. Filter Design Parameters: %Low Pass %Cut off Frequency = 5000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 21 %Design Method Windowing i.e. Rectangular Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 21; % Order of the Filter Fc = 5000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Rect_Win = boxcar(N); % Rectangular Windows Coefficients disp('Windows Coefficient'); disp(Rect_Win) Hn = fir1(N-1,Fc,Rect_Win); % Windowed Filer Coefficients disp('Windowed Filter Coefficient'); disp(Hn) [H,f] = freqz(Hn,1,1024,Fs); %Impulse frequency response Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency (Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency') ylabel ('Phase (radian)')

Magnitude Response 50

Gain (dB)

-50

-100

0.5

1 1.5 Frequency (Hz) Phase Response

2.5 x 10
4

Phase (radian)

-5

-10

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 3

%Assignment No.1 Design of FIR Filters %Part C. Filter Design Parameters: %Low Pass %Cut off Frequency = 5000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 11 %Design Method Windowing i.e. Hamming Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 11; % Order of the Filter Fc = 5000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Ham_Win = hamming(N); % Rectangular Windows Coefficients disp('Windows Coefficient'); disp(Ham_Win) Hn = fir1(N-1,Fc,Ham_Win); % Windowed Filer Coefficients disp('Windowed Filter Coefficient'); disp(Hn) [H,f] = freqz(Hn,1,512,Fs); %Unit Impulse frequency Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f/5000,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency (Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency') ylabel ('Phase (radian)')

Magnitude Response 50 0
Gain (dB)

-50 -100 -150

0.5

1 1.5 Frequency (Hz) Phase Response

2.5 x 10
4

0
Phase (radian)

-5

-10

-15

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 4

%Assignment No.1 Design of FIR Filters %Part D. Filter Design Parameters: %Low Pass %Cut off Frequency = 5000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 21 %Design Method: Windowing i.e. Hamming Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 21; % Order of the Filter Fc = 5000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Ham_Win = hamming(N); % Rectangular Windows Coefficients disp('Windows Coefficient'); disp(Ham_Win) Hn = fir1(N-1,Fc,Ham_Win); % Windowed Filer Coefficients disp('Windowed Filter Coefficients'); disp(Hn) [H,f] = freqz(Hn,1,1024,Fs); %Unit Impulse Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency (Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency') ylabel ('Phase (radian)')

Magnitude Response 0

Gain (dB)

-50

-100

-150

0.5

1 1.5 Frequency (Hz) Phase Response

2.5 x 10
4

0
Phase (radian)

-5

-10

-15

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 5

%Assignment No.1 Design of FIR Filters %Part E. Filter Design Parameters: %High Pass Filter %Cut off Frequency = 2000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 21 %Design Method: Windowing i,e Hamming Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 21; % Order of the Filter Fc = 2000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Ham_Win = hamming(N); % Rectangular Windows Coefficients disp('Window Coefficients'); disp(Ham_Win) Hn = fir1(N-1,Fc,'high',Ham_Win); % Windowed Filer Coefficients disp('Windowed Filter Coefficients'); disp(Hn) [H,f] = freqz(Hn,1,1024,Fs); % Impulse response vector Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency(Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency ') ylabel ('Phase (radian)')

Magnitude Response 5 0
Gain (dB)

-5 -10 -15

0.5

1 1.5 Frequency(Hz) Phase Response

2.5 x 10
4

0
Phase (radian)

-10 -20 -30 -40

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 6

%Assignment No.1 Design of FIR Filters %Part E. Filter Design Parameters: %High Pass Filter %Cut off Frequency = 2000Hz, Sampling Frequency 50000Hz %Filter Length Or Order of Filter N = 21 %Design Method: Windowing i.e. Hamming Window Fs = 50000; %Sampling Frequency Fn = Fs/2; % Nyquist Frequency N = 21; % Order of the Filter Fc = 2000/Fn; % In MATLAB the cutoff frequency should be normalized to Half % of the sampling frequency Rac_Win = boxcar(N); % Rectangular Windows Coefficients disp('Window Coefficients'); disp(Ham_Win) Hn = fir1(N-1,Fc,'high',Rac_Win); % Windowed Filter Coefficients disp('Windowed Filter Coefficients'); disp(Hn) [H,f] = freqz(Hn,1,512,Fs); %Impulse input Mag = 20*log10(abs(H)); % magnitude in Log or in dB subplot(2,1,1); plot(f,Mag); grid on % Real frequency plot title('Magnitude Response') xlabel('Frequency (Hz)') ylabel ('Gain (dB)') subplot(2,1,2); phasez(Hn) % Phase plot xlabel('Frequency ') ylabel ('Phase (radian)')

Magnitude Response 20 0

Gain (dB)

-20 -40 -60

0.5

1 1.5 Frequency (Hz) Phase Response

2.5 x 10
4

10

Phase (radian)

0 -10 -20 -30

0.1

0.2

0.3

0.4

0.5 0.6 Frequency

0.7

0.8

0.9

Page 7

Digital filter design is more an art than a science: the art of finding an acceptable compromise between conflicting constraints. FIR filters are characterized by a linear phase and a constant group delay. The bad side is a high order of the filter which means higher complexity. A linear phase characteristic is the main advantage of FIR filters. If a linear phase is not an issue, FIR filters are not a good choice. Instead, IIR have much lower order with almost the same effects. However, IIR Filters have a very nonlinear phase characteristics. Rectangular Window: Rectangular window has lowest attenuation in stop band, highest oscillations in pass band and narrowest transition zone (2fs/N, where fs is the sampling frequency and N is the filters order). Hamming Window: Hamming window is characterized by greater attenuation in stop band, smaller oscillations in pass band and lesser selectivity and transition zone is 4fs/N, where fs is sampling frequency and N is filters order.

Page 8

Vous aimerez peut-être aussi