代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.29 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % bandpass
ws1 = 0.25*pi; wp1 = 0.4*pi; wp2 = 0.6*pi; ws2 = 0.75*pi;
As = 50; Rp = 1; [delta1, delta2] = db2delta(Rp, As);
deltaH = max(delta1,delta2); deltaL = min(delta1,delta2); f = [ws1, wp1, wp2, ws2]/pi; m = [0, 1, 0]; delta = [delta2, delta1, delta2]; [N, f, m, weights] = firpmord(f, m, delta);
N h = firpm(N, f, m, weights);
[db, mag, pha, grd, w] = freqz_m(h, [1]);
delta_w = 2*pi/1000;
ws1i = floor(ws1/delta_w)+1; wp1i = floor(wp1/delta_w)+1;
ws2i = floor(ws2/delta_w)+1; wp2i = floor(wp2/delta_w)+1; Asd = -max(db(1:1:ws1i)) N = N + 2 % Length M=25
h = firpm(N, f, m, weights); [db, mag, pha, grd, w] = freqz_m(h, [1]);
Asd = -max(db(1:1:ws1i)) M = N + 1
l = 0:M-1;
%% --------------------------------------------------
%% Type-1 BPF
%% --------------------------------------------------
[Hr, ww, a, L] = Hr_Type1(h); Rp = -(min(db(floor(wp1/delta_w)+1 :1: floor(wp2/delta_w)))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(floor(ws2/delta_w)+1 : 1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1_db, delta2_db] = db2delta(Rp, As) % Plot
figure('NumberTitle', 'off', 'Name', 'Problem 7.29 h(n), Parks-McClellan Method')
set(gcf,'Color','white');
subplot(2,2,1); stem([0:M-1], h); axis([0 M-1 -0.5 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response, M=25'); subplot(2,2,2); plot(w/pi, db); axis([0 1 -90 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-53,-9,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['53';' 9';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.33,0.4,0.6,0.66,0.75,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); subplot(2,2,3); plot(ww/pi, Hr); axis([0, 1, -0.2, 1.2]); grid on;
xlabel('frequency in \pi nuits'); ylabel('Hr(w)'); title('Amplitude Response');
set(gca,'XTickMode','manual','XTick',[0,0.25,0.33,0.4,0.6,0.66,0.75,1])
set(gca,'YTickMode','manual','YTick',[0,1]); subplot(2,2,4);
sb1w = ww(1:1:ws1i)/pi; sb1e = Hr(1:1:ws1i);
pbw = ww(wp1i:wp2i)/pi; pbe = Hr(wp1i:wp2i)-1;
sb2w = ww(ws2i:501)/pi; sb2e = Hr(ws2i:501);
plot(sb1w,sb1e,pbw,pbe*(delta2/delta1),sb2w,sb2e); % weighted error
%plot(sb1w,sb1e,pbw,pbe,sb2w,sb2e); % error axis([0, 1, -deltaL, deltaL]); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)');
title('Weighted Error');
%title('Error Response');
set(gca,'XTickMode','manual','XTick',f)
set(gca,'YTickMode','manual','YTick',[-deltaL, 0,deltaL]);
set(gca,'XGrid','on','YGrid','on') figure('NumberTitle', 'off', 'Name', 'Problem 7.29a Parks-McClellan Method')
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -90 10]);
set(gca,'YTickMode','manual','YTick',[-53,-9,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['53';' 9';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.4,0.6,0.75,1,1.25,1.4,1.6,1.75,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.25,0.4,0.6,0.75,1,1.25,1.4,1.6,1.75,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.29 AmpRes of h(n), Parks-McClellan 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_db ,0,delta2_db , 1-delta1_db, 1, 1+delta1_db]);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.4,0.6,0.75,1]);

  运行结果:

阶数N=22时,阻带衰减43dB,不满足要求。

所以增大N,当N=24时,As=52dB,滤波器长度M=25

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

  1. 《DSP using MATLAB》Problem 8.29

    来汉有一月,往日的高温由于最近几个台风沿海登陆影响,今天终于下雨了,凉爽了几个小时. 接着做题. %% ------------------------------------------------ ...

  2. 《DSP using MATLAB》Problem 5.30

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

  3. 《DSP using MATLAB》Problem 8.28

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

  4. 《DSP using MATLAB》Problem 8.27

    7月底,又一个夏天,又一个火热的夏天,来到火炉城武汉,天天高温橙色预警,到今天已有二十多天. 先看看住的地方 下雨的时候是这样的 接着做题 代码: %% ----------------------- ...

  5. 《DSP using MATLAB》Problem 8.26

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

  6. 《DSP using MATLAB》Problem 7.27

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

  7. 《DSP using MATLAB》Problem 7.26

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

  8. 《DSP using MATLAB》Problem 7.25

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

  9. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. MR/hive/shark/sparkSQL

    shark完全兼容hive,完全兼容MR,它把它们替代.类SQL查询,性能比hive高很多 sparkSQL比shark更快.shark严重依赖hive,hive慢,无法优化. SparkSQL和sh ...

  2. windows sdk版本 之 并查集生成迷宫

    #include <cstdlib> #include <ctime> #include<algorithm> using namespace std; exter ...

  3. 关于Unity中脚本

    脚本编译: Unity可以把脚本编译为DLL,DLL将在运行时编译运行.这样可以提高执行 的速度,比传统的JavaScritp快20倍. 脚本具体的编译需要以下4步. 1: 所有的"Stan ...

  4. 026_JDBC

    JDBC简介 JDBC(Java DataBase Connectivity,Java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编 ...

  5. POJ - 2778 ~ HDU - 2243 AC自动机+矩阵快速幂

    这两题属于AC自动机的第二种套路通过矩阵快速幂求方案数. 题意:给m个病毒字符串,问长度为n的DNA片段有多少种没有包含病毒串的. 根据AC自动机的tire图,我们可以获得一个可达矩阵. 关于这题的t ...

  6. Activiti学习笔记2 — HelloWorld

    一. Maven的POM配置文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="htt ...

  7. 分析Hive表和分区的统计信息(Statistics)

    类似于Oracle的分析表,Hive中也提供了分析表和分区的功能,通过自动和手动分析Hive表,将Hive表的一些统计信息存储到元数据中. 表和分区的统计信息主要包括:行数.文件数.原始数据大小.所占 ...

  8. linux系统使用小记

    1.解决Ubuntu不能正常使用vi的问题.sudo apt-get remove vim-common   sudo apt-get install vim 2.备份linux系统,注意,有的优盘单 ...

  9. 人脸识别的LOSS(上)

    超多分类的Softmax 2014年CVPR两篇超多分类的人脸识别论文:DeepFace和DeepID Taigman Y, Yang M, Ranzato M A, et al. Deepface: ...

  10. Linux下常用操作

    ************************ 镜像操作 ************************************* screen -s name 新建 screen -r name ...