《DSP using MATLAB》Problem 8.41

代码:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 8.41.2 \n\n'); banner();
%% ------------------------------------------------------------------------ % Digital lowpass Filter Specifications:
wplp = 0.4*pi; % digital passband freq in rad
wslp = 0.5*pi; % digital stopband freq in rad
Rp = 1.0; % passband ripple in dB
As = 50.0; % stopband attenuation in dB Ripple = 10 ^ (-Rp/20) % passband ripple in absolute
Attn = 10 ^ (-As/20) % stopband attenuation in absolute fprintf('\n*******Digital lowpass, Coefficients of DIRECT-form***********\n');
[blp, alp] = cheb2lpf(wplp, wslp, Rp, As);
[C, B, A] = dir2cas(blp, alp) % Calculation of Frequency Response:
[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp); % ---------------------------------------------------------------
% find Actual Passband Ripple and Min Stopband attenuation
% ---------------------------------------------------------------
delta_w = 2*pi/1000;
Rp_lp = -(min(dblp(1:1:ceil(wplp/delta_w)+1))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_lp); As_lp = -round(max(dblp( ceil(wslp/delta_w)+1:1:501 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_lp); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.41.1 Chebyshev-2 lowpass by cheb2lpf function')
set(gcf,'Color','white');
M = 2; % Omega max subplot(2,2,1); plot(wwlp/pi, maglp); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Lowpass Filter Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.8913, 1]); subplot(2,2,2); plot(wwlp/pi, dblp); axis([0, M, -100, 2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Lowpass Filter Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-80, -60, -50, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['80'; '60'; '50';'1 ';' 0']); subplot(2,2,3); plot(wwlp/pi, phalp/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Lowpass Filter Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,4); plot(wwlp/pi, grdlp); axis([0, M, 0, 50]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Lowpass Filter Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:20:50]); % ------------------------------------------------------------
% PART 2 A/D and Reconstruction
% ------------------------------------------------------------ % Discrete time signal, Samples of analog signal xa(t)
Ts = 0.01; % sample intevel, second
Fs = 1/Ts; % sample frequency, Hz
n1_start = 0; n1_end = 500;
n1 = [n1_start:1:n1_end];
nTs = n1 * Ts; % [0, 5]s xn1 = 3 * sin(40*pi*nTs) + 3 * cos(50*pi*nTs); % digital signal figure('NumberTitle', 'off', 'Name', 'Problem 8.41 xn1')
set(gcf,'Color','white');
subplot(2,1,1); stem(n1, xn1);
xlabel('n'); ylabel('x(n)');
title('xn sequence'); grid on; % ----------------------------
% DTFT of xn1
% ----------------------------
M = 500;
[X1, w] = dtft1(xn1, n1, M); magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1); %% --------------------------------------------------------------------
%% START X(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.41 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|');
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.41 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');
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
%% ------------------------------------------------------------------- % -----------------------------------------
% Reconstruction
% methods: ZOH FOH spline sinc
% -----------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction xa(t) by ZOH');
set(gcf,'Color','white');
subplot(1,1,1); stairs(nTs*100, xn1); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from x1(n) using Zero-Order-Hold function');
xlabel('t in msec units.'); ylabel('xa(n)'); hold on;
stem(nTs*100, xn1); gtext('Ts = 0.01 sec'); hold off; figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction xa(t) by FOH');
set(gcf,'Color','white');
subplot(1,1,1); plot(nTs*100, xn1); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from x1(n) using First-Order-Hold');
xlabel('t in msec units.'); ylabel('xa(n)'); hold on;
stem(nTs*100, xn1); gtext('Ts = 0.01 sec'); hold off; % Reconstruction by spline function
Dt = 0.005; t = 0:Dt:5; xa = spline(nTs, xn1, t);
figure('NumberTitle', 'off', 'Name', sprintf('Problem 8.41.2 Reconstruction xa(t) by spline, Ts = %.4fs', Ts));
set(gcf,'Color','white');
%subplot(2,1,1);
plot(100*t, xa); xlabel('t in ms units'); ylabel('x');
title(sprintf('Reconstructed Signal from x1(n) using spline function')); grid on; hold on;
stem(100*nTs, xn1); gtext('spline'); %% --------------------------------------------------------------------
%% Analog Signal reconstructed by sinc(x) function
%% -------------------------------------------------------------------- Dt = 0.005; t = 0:Dt:5;
xa = xn1 * sinc(Fs*(ones(length(n1),1)*t - nTs'*ones(1,length(t)))) ; figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction by sinc function');
set(gcf,'Color','white');
subplot(1,1,1); plot(t*100, xa, 'r'); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from x1(n) using sinc function');
xlabel('t in msec units.'); ylabel('xa(n)'); hold on;
stem(nTs*100, xn1, 'b', 'filled'); gtext('Ts=0.01 msec'); hold off; % --------------------------------------------
% PART 3: Filter and D/A
% --------------------------------------------
yn1 = filter(blp, alp, xn1); % ----------------------------
% DTFT of yn1
% ----------------------------
M = 500;
[Y1, w] = dtft1(yn1, n1, M); magY1 = abs(Y1); angY1 = angle(Y1); realY1 = real(Y1); imagY1 = imag(Y1); %% --------------------------------------------------------------------
%% START Y1(w)'s mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.41 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.41 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
%% ------------------------------------------------------------------- % -----------------------------------------
% Reconstruction
% methods: ZOH FOH spline sinc
% -----------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction ya(t) by ZOH');
set(gcf,'Color','white');
subplot(1,1,1); stairs(nTs*100, yn1); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from y1(n) using Zero-Order-Hold function');
xlabel('t in msec units.'); ylabel('ya(n)'); hold on;
stem(nTs*100, yn1); gtext('Ts = 0.01 sec'); hold off; figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction ya(t) by FOH');
set(gcf,'Color','white');
subplot(1,1,1); plot(nTs*100, yn1); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from y1(n) using First-Order-Hold');
xlabel('t in msec units.'); ylabel('ya(n)'); hold on;
stem(nTs*100, yn1); gtext('Ts = 0.01 sec'); hold off; % Reconstruction by spline function
Dt = 0.005; t = 0:Dt:5; ya = spline(nTs, yn1, t);
figure('NumberTitle', 'off', 'Name', sprintf('Problem 8.41.2 Reconstruction ya(t) by spline, Ts = %.4fs', Ts));
set(gcf,'Color','white');
%subplot(2,1,1);
plot(100*t, ya); xlabel('t in ms units'); ylabel('ya');
title(sprintf('Reconstructed Signal from y1(n) using spline function')); grid on; hold on;
stem(100*nTs, yn1); gtext('spline'); %% --------------------------------------------------------------------
%% Analog Signal reconstructed by sinc(x) function
%% -------------------------------------------------------------------- Dt = 0.005; t = 0:Dt:5;
ya = yn1 * sinc(Fs*(ones(length(n1),1)*t - nTs'*ones(1,length(t)))) ; figure('NumberTitle', 'off', 'Name', 'Problem 8.41.2 Reconstruction by sinc function');
set(gcf,'Color','white');
subplot(1,1,1); plot(t*100, ya, 'r'); grid on; %axis([0,1,0,1.5]);
title('Reconstructed Signal from y1(n) using sinc function');
xlabel('t in msec units.'); ylabel('ya(n)'); hold on;
stem(nTs*100, yn1, 'b', 'filled'); gtext('Ts=0.01 msec'); hold off;
运行结果:
通带、阻带指标,绝对值单位

采用cheb2lpf函数,设计的Chebyshev-2型数字低通,系统函数串联形式系数

低通,幅度谱、相位谱和群延迟响应

采样信号的谱(DTFT变换),可看出,有两个数字频率分量,0.4π和0.5π

将采样信号通过设计的Chebyshev-2数字低通,得到输出y(n),其频谱如下,可看出,滤除了0.5π分量,仅保留0.4π分量

对离散信号y(n)采用sinc(插值函数)重建连续信号,如下图

《DSP using MATLAB》Problem 8.41的更多相关文章
- 《DSP using MATLAB》Problem 8.45
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 8.44
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- Flink开发-IDEA scala开发环境搭建
现在大数据相关服务,越来越倾向于使用scala语言,scala函数式编程的优势我不多赘述.最明显的一个优点,代码简洁.看个WordCount实现对比: Java版WordCount Execution ...
- Spring Boot 2.X 实现文件上传(三)
使用 SpringBoot 项目完成单个.多个文件的上传处理,并将上传的文件保存到指定目录下. 代码演示案例 所有的 HTML 页面文件 index.html <!DOCTYPE html> ...
- leetcode-685-冗余连接②
题目描述: 参考后提交:并查集: class Solution: def findRedundantDirectedConnection(self, edges: List[List[int]]) - ...
- NX二次开发-NXOpen获取边的端点NXOpen::Edge::GetVertices
NX9+VS2012 #include <NXOpen/Features_BlockFeatureBuilder.hxx> #include <NXOpen/Features_Fea ...
- ES6 箭头函数this指向
箭头函数有几个使用注意点. (1)函数体内的this对象,就是定义时所在的对象,而不是使用时所在的对象. (2)不可以当作构造函数,也就是说,不可以使用new命令,否则会抛出一个错误. (3)不可以使 ...
- mysql数据库分页查询优化
原博:MySQL单表百万数据记录分页性能优化 limit优化 当数据很多需要进行分页查询时:需要先查出第一条数据的id然后根据id查询大于id的数据 limt 一页的数据量 1. 直接用limit ...
- Perl 数组应用详解(push, pop, shift, unshift)
Perl的数组操作有四大常用函数: push:从数组的末尾加入元素.pop :从数组的末尾取出元素 shift: 从数组的开头取出元素unshift:从数组的开头加入元素 1.push #!/usr/ ...
- Invalid Rom
问题描述 原因说明 这多半是因为单片机超频被锁,就是HSE_VALUE设置的与实际值不一致,容易造成这个问题. 解放方法 1. 先正确配置 HSE_VLAUE, 看HSE_VALUE 修改问题. 2. ...
- Python3 From Zero——{最初的意识:006~数据编码与处理}
一.读写CSV数据: #!/usr/bin/env python3 #-*- coding=utf8 -*- import csv with open('kxtx.csv', 'rt') as f: ...
- 剑指offer——26树的子结构
题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 题解: 注意,所谓的子结构,是树的形状和值相同,并非判断B是不是A的一部分[如果是这样,那就是 ...