《DSP using MATLAB》示例Example 8.28

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

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

% Digital Filter Specifications:   Chebyshev-1 hignpass
wp = 0.6*pi;                     % digital passband freq in rad
ws = 0.4586*pi;                  % digital stopband freq in rad
Rp = 1;                          % passband ripple in dB
As = 15;                         % stopband attenuation in dB

% Calculation of Chebyshev-1 filter parameters:
[N, wn] = cheb1ord(wp/pi, ws/pi, Rp, As);

% Digital Chebyshev-1 Highpass Filter Design:
[bhp, ahp] = cheby1(N, Rp, wn, 'high');

[C, B, A] = dir2cas(bhp, ahp)

% Calculation of Frequency Response:
%[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp);
[dbhp, maghp, phahp, grdhp, wwhp] = freqz_m(bhp, ahp);


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

figure('NumberTitle', 'off', 'Name', 'Exameple 8.28')
set(gcf,'Color','white'); 
M = 1;                          % Omega max

subplot(2,2,1); plot(wwhp/pi, maghp); axis([0, M, 0, 1.2]); grid on;
xlabel(' frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.1778, 0.8913, 1]);

subplot(2,2,2); plot(wwhp/pi, dbhp); axis([0, M, -30, 2]); grid on;
xlabel(' frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-30, -15, -1, 0]);

subplot(2,2,3); plot(wwhp/pi, phahp/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]);

subplot(2,2,4); plot(wwhp/pi, grdhp); axis([0, M, 0, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Samples'); title('Highpass Filter Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:2:10]);

  运行结果:

 

posted @ 2017-04-20 12:10  跑啊跑  阅读(130)  评论(0编辑  收藏  举报