代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 8.42 \n\n'); banner();
%% ------------------------------------------------------------------------ % Digital Filter Specifications: Elliptic bandstop
wsbs = [0.40*pi 0.48*pi]; % digital stopband freq in rad
wpbs = [0.25*pi 0.75*pi]; % digital passband freq in rad Rp = 1.0 % passband ripple in dB
As = 80 % stopband attenuation in dB Ripple = 10 ^ (-Rp/20) % passband ripple in absolute
Attn = 10 ^ (-As/20) % stopband attenuation in absolute % Calculation of Elliptic filter parameters: [N, wn] = ellipord(wpbs/pi, wsbs/pi, Rp, As); fprintf('\n ********* Elliptic Digital Bandstop Filter Order is = %3.0f \n', 2*N) % Digital Elliptic bandstop Filter Design:
[bbs, abs] = ellip(N, Rp, As, wn, 'stop'); [C, B, A] = dir2cas(bbs, abs) % Calculation of Frequency Response:
[dbbs, magbs, phabs, grdbs, wwbs] = freqz_m(bbs, abs); % ---------------------------------------------------------------
% find Actual Passband Ripple and Min Stopband attenuation
% ---------------------------------------------------------------
delta_w = 2*pi/1000;
Rp_bs = -(min(dbbs(1:1:ceil(wpbs(1)/delta_w+1)))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_bs); As_bs = -round(max(dbbs(ceil(wsbs(1)/delta_w)+1:1:ceil(wsbs(2)/delta_w)+1))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_bs); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Elliptic bs by ellip function')
set(gcf,'Color','white');
M = 1; % Omega max subplot(2,2,1); plot(wwbs/pi, magbs); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.01, 0.8913, 1]); subplot(2,2,2); plot(wwbs/pi, dbbs); axis([0, M, -120, 2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [ -80, -40, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['80'; '40';' 0']); subplot(2,2,3); plot(wwbs/pi, phabs/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]); subplot(2,2,4); plot(wwbs/pi, grdbs); axis([0, M, 0, 50]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:20:50]); % ------------------------------------------------------------
% PART 2
% ------------------------------------------------------------ % Discrete time signal
Ts = 1; % sample intevals
n1_start = 0; n1_end = 200;
n1 = [n1_start:n1_end]; % [0:200] xn1 = sin(0.44*pi*n1); % digital signal % ----------------------------
% DTFT of xn1
% ----------------------------
M = 500;
[X1, w] = dtft1(xn1, n1, M); %magX1 = abs(X1);
angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);
magX1 = sqrt(realX1.^2 + imagX1.^2); %% --------------------------------------------------------------------
%% START X(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.42 X1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.44, 0.6, 0.8, 1.0, 1.2, 1.4, 1.56, 1.8, 2]); subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('digital frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 8.42 X1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realX1); grid on;
title('Real Part');
xlabel('digital frequency in \pi units'); ylabel('Real');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.44, 0.6, 0.8, 1.0, 1.2, 1.4, 1.56, 1.8, 2]); subplot(2,1,2); plot(w/pi, imagX1); grid on;
title('Imaginary Part');
xlabel('digital frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- % ------------------------------------------------------------
% PART 3
% ------------------------------------------------------------
yn1 = filter(bbs, abs, xn1);
n2 = n1; % ----------------------------
% DTFT of yn1
% ----------------------------
M = 500;
[Y1, w] = dtft1(yn1, n2, M); %magY1 = abs(Y1);
angY1 = angle(Y1); realY1 = real(Y1); imagY1 = imag(Y1);
magY1 = sqrt(realY1.^2 + imagY1.^2); %% --------------------------------------------------------------------
%% START Y1(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Y1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magY1); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angY1/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('digital frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Y1 DTFT');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realY1); grid on;
title('Real Part');
xlabel('digital frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagY1); grid on;
title('Imaginary Part');
xlabel('digital frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END Y1's mag ang real imag
%% ------------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.42 x(n) and y(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n1, xn1);
xlabel('n'); ylabel('x(n)');
title('xn sequence'); grid on;
subplot(2,1,2); stem(n1, yn1);
xlabel('n'); ylabel('y(n)');
title('yn sequence'); grid on;

  运行结果:

我自己假设通带1dB,阻带衰减80dB。

在此基础上设计指标,绝对单位,

ellip函数(MATLAB工具箱函数)得到Elliptic带阻滤波器,阶数为10,系统函数串联形式系数如下图。

Elliptic带阻滤波器,幅度谱、相位谱和群延迟响应

输入离散时间信号x(n)的谱如下,可看出,频率分量0.44π

通过带阻滤波器后,得到的输出y(n)的谱,好像变乱了,o(╥﹏╥)o

输入和输出的离散时间序列如下图

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

  1. 《DSP using MATLAB》Problem 7.14

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

  2. 《DSP using MATLAB》Problem 7.27

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

  3. 《DSP using MATLAB》Problem 7.26

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

  4. 《DSP using MATLAB》Problem 7.25

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

  5. 《DSP using MATLAB》Problem 7.24

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

  6. 《DSP using MATLAB》Problem 7.23

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...

  7. 《DSP using MATLAB》Problem 7.16

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

  8. 《DSP using MATLAB》Problem 7.15

    用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  9. 《DSP using MATLAB》Problem 7.13

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

随机推荐

  1. c#委托(Delegates)--基本概念及使用 转发

    在我这菜鸟理解上,委托就是可以用方法名调用另一方法的便捷方法,可以简化switch等语句的重复.最近做项目的时候恰好需要用到委托,便来复习及学习委托的使用.嗯...本人以前并没有用过,只是稍微知道而已 ...

  2. static变量、static函数与普通变量、普通函数的区别

    转自:http://blog.163.com/sunshine_linting/blog/static/44893323201191294825184/ 全局变量(外部变量)的说明之前再冠以stati ...

  3. DLL 调用 对话框 以及 如何获取调用dll 应用程序(窗口程序)的窗口句柄

    1.一般创建需要的窗口,转换成相应的窗口类: 声明一个导出函数,来处理窗口的显示,如: CTest test; extern "C" __declspec(dllexport) v ...

  4. JHipster研究

    liquibase工作原理: master.xml用来维护所有变更记录文件引用 changelog文件夹用来保存具体的变更细节 系统启动时会比较master.xml中include的file,应用差异 ...

  5. swiper实现上下滑动翻页,内置内容页也滚动

    如果我猜的没错,是全网(哈哈)比较少的成功解决方案,如需要转载,请声明并转载出处. swiper实现了上下滑动翻页,但是有几个页面的内容显示不完.如果一页显示不完时可以滑动查看,应该怎么做?这个是我多 ...

  6. kafka相关业务必会操作命令整理

    参考:https://kafka.apache.org 服务相关命令 1.启动/停止zk > bin/zookeeper-server-start.sh config/zookeeper.pro ...

  7. scala 集合类型

    Iterable 是序列(Seq), 集(Set) 映射(Map)的特质 序列式有序的集合如数组和列表 集合可以通过== 方法确定对每个对象最多包含一个 映射包含了键值映射关系的集合 列表缓存: 使用 ...

  8. VMware中 CentOS7挂载windows共享文件夹

    在编译自己的hadoop时,不想再次在虚拟机中下载jar包,就想到了挂载自己本地的maven仓库,使用本地仓库来进行编译,这里就需要使用VMware的VMware Tools了,直接复制官方文档如下 ...

  9. String.join() --Java8中String类新增方法

    序言 在看别人的代码时发现一个方法String.join(),因为之前没有见过所以比较好奇. 跟踪源码发现源码很给力,居然有用法示例,以下是源码: /** * Returns a new String ...

  10. HttpURLConnection模拟登录学校的正方教务系统

    教务系统登录界面 如图1-1 1-1 F12-->network查看登录教务系统需要参数: __VIEWSTAT txtUserName TextBox2 txtSecretCode Radio ...