0% found this document useful (0 votes)
50 views4 pages

Filters Assignment Athar

The document describes MATLAB code for designing and analyzing various digital filters including: 1) A low pass filter with a passband of 100 Hz, stopband attenuation of 40 dB, and other specifications. The code designs the filter and plots its frequency response. 2) A high pass filter with a passband of 1 kHz, stopband of 1.5 kHz, and other specs. Increased order is needed to achieve desired stopband attenuation. 3) A half band low pass filter with a passband of 2 kHz, stopband attenuation of 45 dB, and other specs. The code designs the filter and plots its frequency response.

Uploaded by

Ubaid Imtiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Filters Assignment Athar

The document describes MATLAB code for designing and analyzing various digital filters including: 1) A low pass filter with a passband of 100 Hz, stopband attenuation of 40 dB, and other specifications. The code designs the filter and plots its frequency response. 2) A high pass filter with a passband of 1 kHz, stopband of 1.5 kHz, and other specs. Increased order is needed to achieve desired stopband attenuation. 3) A half band low pass filter with a passband of 2 kHz, stopband attenuation of 45 dB, and other specs. The code designs the filter and plots its frequency response.

Uploaded by

Ubaid Imtiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 7.

6:
Requirements:
Low pass filter; AS = 40 dB; fp = 100 Hz; AP = 0.05 dB; TW = 10 Hz; FS = 1024 Hz

Solution
Converting AS to δS gives δS = 0.01

Similarly: δP = 0.005

MATLAB Code
Fs = 1024; % Sampling Frequency
ds = 0.01; % Delta s
dp = 0.005; % Delta p
fp = 100; % Passband
fs = 110; % Stopband = fp + TW

[n, fo, mo, w] = firpmord([fp, fs], [1, 0], [dp, ds], Fs); % Order +
Normalization
b = firpm(n, fo, mo, w); % Filter Coefficients
[H, f] = freqz(b, 1, 512, 1024); % Frequency Response
mag = 20*log10(abs(H));

plot(f, mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');

Frequency Response
10

-10

-20

-30
Magnitude (dB)

-40

-50

-60

-70

-80

-90
0 100 200 300 400 500 600
Frequency (Hz)
Question 7.7:
Requirements:
HPF; fp = 1 kHz; fs = 1.5 kHz; FS = 10 kHz; δS = 0.01; δP = 0.01

Solution
Normalizing the frequencies gives fp = 0.1 ; fs = 0.15

MATLAB Code
N = 41; % Filter order
F = 2*[0, 0.1, 0.15, 0.5]; % Normalized frequencies
A = [0, 1, 0, 0];

b = firpm(N, F, A, 'differentiator');
[H, f] = freqz(b, 1, 1024, 10000);
mag = 20*log10(abs(H));

plot(f, mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');

Frequency Response
20

-20 X: 1504
Y: -30.36
Magnitude (dB)

-40

-60

-80

-100
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)

Comments
As can be seen from the figure, desired attenuation of >40 dB has not been achieved. We can achieve
this by increasing the order to N = 57.
10

-10

-20

-30
Magnitude (dB)

X: 1499
Y: -40.26
-40

-50

-60

-70

-80

-90
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)

Question 7.19:
Requirements:
Half band LPF; AS = 45 dB; fp = 2 kHz; AP = 0.5 dB; FS = 10 kHz

Solution
Calculating deltas gives: δS = 0.0056 and δP = 0.0592. As half band filter uses equal deltas, we choose δ S =
δP = 0.005.

Fs
Calculating fs: f s= −f p =3 kHz
2
MATLAB Code
Fs = 5e3; % This is Fs/2
fp = 2e3; % Passband
fs = 3000; % Stopband
TW = (fs-fp)/Fs; % Transition band
N = 29; % Approximated by using kaiserord()
d = fdesign.interpolator(2,'halfband','N,TW',N+1,TW);
HBka = design(d,'kaiserwin','SystemObject',true); % Kaiser-window design
hfvt = fvtool(HBka,'Fs',2*Fs,'Color','white');
Frequency Response
Magnitude Response (dB)
10

-10

-20
Magnitude (dB)

-30

-40

-50

-60

-70

-80
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Frequency (kHz)

You might also like