首页 > 代码库 > 《DSP using MATLAB》 示例 Example 9.16

《DSP using MATLAB》 示例 Example 9.16

技术分享

代码:

%% ------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Exameple 9.16 \n\n‘);

time_stamp = datestr(now, 31);
[wkd1, wkd2] = weekday(today, ‘long‘);
fprintf(‘      Now is %20s, and it is %7s  \n\n‘, time_stamp, wkd2);
%% ------------------------------------------------------------------------

% Given Parameters:
I = 4; D = 3; Rp = 0.1; As = 40; 
wxp = 0.8*pi; wxs1 = 0.9*pi; wxs2 = 0.7*pi;

% Computed Filter Parameters
wp = wxp/I; ws = min((2*pi/I-wxs1/I), (2*pi/D-wxs2/I));    

% Filter Design:
[delta1, delta2] = db2delta(Rp, As); 

[N, F, A, weights] = firpmord([wp, ws]/pi, [1, 0], [delta1, delta2], 2); 
N = ceil(N/2)*2 + 1;
N
F
A
weights

h = firpm(N, F, I*A, weights); 
%delay = N/2;                        % delay imparted by the filter  
% n = [0:length(h)-1];
[Hr, w, a, L] = Ampl_res(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h, 1, w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);

%% -----------------------------------------------------------------
%%                             Plot
%% -----------------------------------------------------------------  


Hf1 = figure(‘units‘, ‘inches‘, ‘position‘, [1, 1, 8, 6], ...
	‘paperunits‘, ‘inches‘, ‘paperposition‘, [0, 0, 6, 4], ...
	‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Exameple 9.16‘);
set(gcf,‘Color‘,‘white‘); 

TF = 10;

subplot(2, 1, 1); 
plot(w/pi, Hr, ‘m‘, ‘linewidth‘, 1.0); axis([0, 1, -0.1, I+0.4]); grid on;
xlabel(‘Frequency in \pi units‘, ‘vertical‘, ‘middle‘); ylabel(‘Amplitude‘, ‘vertical‘, ‘middle‘); 
title(‘Amplitude Response ‘, ‘fontsize‘, TF, ‘vertical‘, ‘baseline‘);
set(gca, ‘xtick‘, [0, wp/pi, ws/pi, 1]); 
set(gca, ‘ytick‘, [0, I]);


subplot(2, 1, 2); 
plot(w/pi, Hdb, ‘m‘, ‘linewidth‘, 1.0); axis([0, 1, -60, 10]); grid on;
xlabel(‘Frequency in \pi units‘, ‘fontsize‘, TF, ‘vertical‘, ‘middle‘);
ylabel(‘Decibels‘, ‘vertical‘, ‘cap‘);
title(‘Log-magnitude Response‘, ‘fontsize‘, TF, ‘vertical‘, ‘baseline‘);
set(gca, ‘xtick‘, [0, wp/pi, ws/pi, 1], ‘ytick‘, [-60, round(min_attn), 0]);

  运行结果:

技术分享

技术分享

        衰减达到40dB。

---------------------------------------------------------------------------

               第9章结束。

---------------------------------------------------------------------------

《DSP using MATLAB》 示例 Example 9.16