forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog7b4a.m
20 lines (20 loc) · 845 Bytes
/
prog7b4a.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
%
% Program name - prog7b4a.m
% m-file for calculating the optimal FIR filter coefficients
% and plotting frequency response for Example 7B.4
%
Fs=50000; % Sampling frequency % Filter length
Ap=1; % Pass band ripple in dB
As=45; % Stop band attenuation in dB
M=[0 1 0]; % Desired magnitude response
F=[10000, 12000, 16000, 18000] ; % Band edge frequencies
dp=(10^(Ap/20)-1)/(10^(Ap/20)+1); % Pass and stop band ripples
ds=10^(-As/20);
dev=[ds dp ds];
[N1, F0, M0, W] = remezord(F, M, dev, Fs); % Determine filter order
[b delta] = remez(N1, F0, M0, W);% Compute the filter coefficients
[H, f] = freqz(b, 1, 1024, Fs); % Compute the frequency response
mag = 20*log10(abs(H)); % of filter and plot it
plot(f, mag), grid on
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')