首页 > 代码库 > 《DSP using MATLAB》示例 Example 9.8
《DSP using MATLAB》示例 Example 9.8
代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(‘\n***********************************************************\n‘); fprintf(‘ <DSP using MATLAB> Exameple 9.8 \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); %% ------------------------------------------------------------------------ I = 5; Rp = 0.1; As = 30; wp = pi/I; ws = wp+pi*0.12; [delta1, delta2] = db2delta(Rp, As); weights = [delta2/delta1, 1]; F = [0, wp, ws, pi]/pi; A = [I, I, 0, 0]; h = firpm(30, F, A, weights); n = [0:length(h)-1]; [Hr, w, a, L] = Hr_Type1(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.8‘); set(gcf,‘Color‘,‘white‘); TF = 10; subplot(2, 2, 1); Hs1 = stem(n, h, ‘filled‘); set(Hs1, ‘markersize‘, 2); axis([-1, length(n), -0.5, 1.5]); grid on; xlabel(‘n‘, ‘vertical‘, ‘bottom‘); ylabel(‘Amplitude‘); title(‘Impulse Response‘, ‘fontsize‘, TF); subplot(2, 2, 3); plot(w/pi, Hr, ‘m‘, ‘linewidth‘, 1.0); axis([0, 1, -1, 6]); grid on; xlabel(‘frequency in \pi units‘, ‘fontsize‘, 10); ylabel(‘Amplitude‘); title(‘ Amplitude Response ‘, ‘fontsize‘, TF); set(gca, ‘xtick‘, [0, wp/pi, ws/pi, 1]); set(gca, ‘ytick‘, [0, I]); subplot(2, 2, 2); plot(w/pi, Hdb, ‘m‘, ‘linewidth‘, 1.0); axis([0, 1, -50, 10]); grid on; xlabel(‘frequency in \pi units ‘); ylabel(‘Decibels‘); title(‘Log-mag Response ‘, ‘fontsize‘, TF); set(gca, ‘xtick‘, [0, wp/pi, ws/pi, 1]); set(gca, ‘ytick‘, [-50, round(min_attn), 0]); subplot(2, 2, 4); lw = length(w)-1; PB = [0:floor(wp/pi*lw)]; HrPB = Hr(PB+1)-I; SB = [ceil(ws/pi*lw):lw]; HrSB = Hr(SB+1); [AX, H1, H2] = plotyy(PB/lw, HrPB, SB/lw, HrSB); delta1 = round(delta1*I*100)/100; delta2 = round(delta2*I*100)/100; set(AX(1), ‘xtick‘, [0, wp/pi, ws/pi, 1]); set(AX(1), ‘ytick‘, [-delta1, 0, delta1], ‘Ycolor‘, ‘g‘); set(AX(2), ‘xtick‘, [0, wp/pi, ws/pi, 1]); set(AX(2), ‘ytick‘, [-delta2, 0, delta2], ‘Ycolor‘, ‘r‘); set(H1, ‘color‘, ‘g‘, ‘linewidth‘, 1); set(H2, ‘color‘, ‘r‘, ‘linewidth‘, 1); title(‘scaled ripples‘, ‘fontsize‘, TF); xlabel(‘Frequency in \pi units‘);
运行结果:
尽管该滤波器通过了原始信号,如果信号是全频带π弧度的,那么邻近的谱能量可能发生泄漏。因此需要更好的设计指标,本节的后面有讨论。
《DSP using MATLAB》示例 Example 9.8
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。