注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数。这里取M=31,过渡带里采样值抄书上的。

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.26 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % highpass, Only Type-1 filter
ws1 = 0.4*pi; wp1 = 0.6*pi; As = 50; Rp = 0.004;
tr_width = (wp1-ws1); T2 = 0.5925; T1=0.1099;
M = 31; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
n = [0:1:M-1]; wc1 = (ws1+wp1)/2; Hrs = [zeros(1,7),T1,T2,ones(1,14),T2,T1,zeros(1,6)]; % Ideal Amp Res sampled
Hdr = [0, 0, 1, 1]; wdl = [0, 0.4, 0.6, 1]; % Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; %% --------------------------------------------------
%% Type-1 BPF
%% --------------------------------------------------
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H, M)); [db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
%[Hr,ww,P,L] = ampl_res(h);
[Hr, ww, a, L] = Hr_Type1(h); Rp = -(min(db(floor(wp1/delta_w)+1 :1: 501))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) % Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.26a FreSamp Method')
set(gcf,'Color','white');
subplot(2,2,1); plot(wl(1:16)/pi, Hrs(1:16), 'o', wdl, Hdr, 'r'); axis([0, 1, -0.1, 1.1]);
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=31,T1=0.5925,T2=0.1099');
grid on; subplot(2,2,2); stem(l, h); axis([-1, M, -0.4, 0.6]); grid on;
xlabel('n'); ylabel('h(n)'); title('Impulse Response'); subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:16)/pi, Hrs(1:16), 'o'); axis([0, 1, -0.2, 1.2]); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]); subplot(2,2,4); plot(w/pi, db); axis([0, 1, -100, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response');
set(gca,'YTickMode','manual','YTick',[-90,-60,-51,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]); figure('NumberTitle', 'off', 'Name', 'Problem 7.26 h(n) FreSamp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
set(gca,'YTickMode','manual','YTick',[-90,-60,-51,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0]); subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.26 AmpRes of h(n), FreSamp Method')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-delta2, 0,delta2, 1-0.0258, 1,1+0.0258]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]); %% ------------------------------------
%% fir2 Method
%% ------------------------------------
f = [0 ws1 wp1 pi]/pi;
m = [0 0 1 1 ];
h_check = fir2(M+1, f, m); % if M is odd, then M+1; order
[db, mag, pha, grd, w] = freqz_m(h_check, [1]);
%[Hr,ww,P,L] = ampl_res(h_check);
[Hr, ww, a, L] = Hr_Type1(h_check); fprintf('\n----------------------------------\n');
fprintf('\n fir2 function Method \n');
fprintf('\n----------------------------------\n'); Rp = -(min(db(floor(wp1/delta_w)+1 :1: 501))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) figure('NumberTitle', 'off', 'Name', 'Problem 7.26 fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, h); axis([0 M-1 -0.4 0.6]); grid on;
xlabel('n'); ylabel('h(n)'); title('Impulse Response'); %subplot(2,2,2); stem(n, w_ham); axis([0 M-1 0 1.1]); grid on;
%xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem([0:M+1], h_check); axis([0 M+1 -0.4 0.6]); grid on;
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-67,-21,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.26 h(n) fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-67,-21,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0]); subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.26 AmpRes of h(n),fir2 Method')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-0.08, 0,0.08, 1-0.04, 1,1+0.04]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);

  运行结果:

振幅响应

《DSP using MATLAB》Problem 7.26的更多相关文章

  1. 《DSP using MATLAB》Problem 8.26

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  2. 《DSP using MATLAB》Problem 4.26

    Y(z)部分分式展开, 零状态响应和零输入响应的部分分式展开,

  3. 《DSP using MATLAB》Problem 5.24-5.25-5.26

    代码: function y = circonvt(x1,x2,N) %% N-point Circular convolution between x1 and x2: (time domain) ...

  4. 《DSP using MATLAB》Problem 7.16

    使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  5. 《DSP using MATLAB》Problem 6.8

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  6. 《DSP using MATLAB》Problem 2.16

    先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...

  7. 《DSP using MATLAB》Problem 7.32

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  8. 《DSP using MATLAB》Problem 7.30

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  9. 《DSP using MATLAB》Problem 7.27

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

随机推荐

  1. react-redux-action

    Action 是把数据从应用(view等)传到 store 的有效载荷,store.dispatch() 将 action 传到 store. //尽量减少在 action 中传递的数据//actio ...

  2. MapReduce实现Apriori算法

    Apiroi算法在Hadoop MapReduce上的实现 输入格式: 一行为一个Bucket 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 ...

  3. java 反射获取方法返回值类型

    //ProceedingJoinPoint pjp //获取方法返回值类型 Object[] args = pjp.getArgs(); Class<?>[] paramsCls = ne ...

  4. Vue移动端项目总结

    使用Vue项目写了一个移动端项目,然后又把项目硬生生的抽离了组件,一直忙着写RN项目没有时间总结心得,今天上午终于下定决心,写点总结. 1.position:absolute: 定位的时候不同手机的浏 ...

  5. MySql主从搭建详细步骤

    环境: linux64位,一台机器两个实例,主库3306端口,从库3307端口 步骤: 一.下载安装 先下载安装mysql,这里使用了5.7.21版本,具体过程不做详细说明,可自行查资料如何下载 二. ...

  6. Android四大组件之Service --- 如何启动和停止Service?

    启动和停止方法主要是通过Intent来实现 以上一篇中的ServiceTest项目为例来启动和停止MyService这个服务 首先修改activity_main.xml中的代码,如下所示:<Li ...

  7. 第4次作业 -- 基于Jenkins的持续集成

    Jenkins 配置使用心得 先在 https://jenkins.io/download/ 下载Jenkins 下载之后安装,在指定的地方找到了初始密码,安装了一些插件之后,Jenkins就可以使用 ...

  8. java 秒时间格式化

    public static String durationFormat(Integer totalSeconds) { if (totalSeconds == null || totalSeconds ...

  9. 原生js实现下拉菜单

    简单给两段代码: html和css部分: <style> .one li{ width:100px; height:30px; line-height:30px; background:u ...

  10. LAD 线性判别分析

    线性判别分析,简称LDA,是一种线性学习方法. 常用来降维,是一种有监督的降维方法,是基于最佳分类效果的降维方法. 核心思想 给定训练样本,带label,设法将样本投影到一条直线上,使得同类样例的投影 ...