代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Exameple 9.12 \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);
%% ------------------------------------------------------------------------ % Given Parameters: D = 2; Rp = 0.1; As = 30; wp = pi/D; ws = wp+0.1*pi; % Filter Design:
[delta1, delta2] = db2delta(Rp, As); [N, F, A, weights] = firpmord([wp, ws]/pi, [1, 0], [delta1, delta2], 2);
h = firpm(N, F, A, weights);
delay = N/2; % delay imparted by the filter %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- % Input signal x1(n) = cos(2*pi*n/16)
n = [0:256]; x = cos(pi*n/8);
n1 = n(1:33); x1 = x(33:65); % for plotting purposes Hf1 = figure('units', 'inches', 'position', [1, 1, 8, 6], ...
'paperunits', 'inches', 'paperposition', [0, 0, 6, 4], ...
'NumberTitle', 'off', 'Name', 'Exameple 9.12');
set(gcf,'Color','white'); TF = 10; subplot(2, 2, 1);
Hs1 = stem(n1, x1, 'filled'); set(Hs1, 'markersize', 2, 'color', 'g');
axis([-2, 34, -1.2, 1.2]); grid on;
xlabel('n', 'vertical', 'middle'); ylabel('Amplitude');
title('Input Singal: x1(n) = cos(\pin/8) ', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0:8:32]);
set(gca, 'ytick', [-1, 0, 1]); % Decimation of x1(n): D = 2
y = upfirdn(x, h, 1, D);
m = delay+1:1:128/D+delay+1; y = y(m); m = 0:16; y = y(16:32); subplot(2, 2, 3);
Hs2 = stem(m, y, 'filled'); set(Hs2, 'markersize', 2, 'color', 'm');
axis([-1, 17, -1.2, 1.2]); grid on;
xlabel('m', 'vertical', 'middle'); ylabel('Amplitude', 'vertical', 'cap');
title('Output Singal: y1(n): D=2', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0:8:32]/D);
set(gca, 'ytick', [-1, 0, 1]); % Input signal x2(n) = cos(8*pi*n/16)
n = [0:256]; x = cos(8*pi*n/(16));
n2 = n(1:33); x2 = x(33:65); % for plotting purposes subplot(2, 2, 2);
Hs3 = stem(n2, x2, 'filled'); set(Hs3, 'markersize', 2, 'color', 'g');
axis([-2, 34, -1.2, 1.2]); grid on;
xlabel('n', 'vertical', 'middle'); ylabel('Amplitude', 'vertical', 'cap');
title('Input Singal: x2(n)=cos(\pin/2) ', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0:8:32]);
set(gca, 'ytick', [-1, 0, 1]); % Decimation of x2(n): D = 2
y = upfirdn(x, [h], 1, D); % y = downsample(conv(x,h),2);
m = delay+1:1:128/D+delay+1; y = y(m); m = 0:16; y = y(16:32); subplot(2, 2, 4);
Hs4 = stem(m, y, 'filled'); set(Hs4, 'markersize', 2, 'color', 'm');
axis([-1, 17, -1.2, 1.2]); grid on;
xlabel('m', 'vertical', 'middle'); ylabel('Amplitude', 'vertical', 'cap');
title('Output Singal: y2(n): D=2', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0:8:32]/D);
set(gca, 'ytick', [-1, 0, 1]);

  运行结果:

左半边的图展示了x1(n)和相应减采样结果信号y1(n),右半边展示了x2(n)和相应减采样y2(n)。两种情况下减采样
看上去都正确。如果我们选π/2以上的任何频率,那么滤波器将会衰减或消除信号。

《DSP using MATLAB》 示例 Example 9.12的更多相关文章

  1. 《DSP using MATLAB》Problem 7.12

    阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  2. 《DSP using MATLAB》Problem 6.12

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

  3. 《DSP using MATLAB》Problem 5.12

    1.从别的地方找的证明过程: 2.代码 function x2 = circfold(x1, N) %% Circular folding using DFT %% ----------------- ...

  4. 《DSP using MATLAB》Problem 8.12

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

  5. DSP using MATLAB 示例 Example3.12

    用到的性质 代码: n = -5:10; x = sin(pi*n/2); k = -100:100; w = (pi/100)*k; % freqency between -pi and +pi , ...

  6. DSP using MATLAB 示例Example2.12

    代码: b = [1]; a = [1, -0.9]; n = [-5:50]; h = impz(b,a,n); set(gcf,'Color','white'); %subplot(2,1,1); ...

  7. DSP using MATLAB 示例Example3.21

    代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*a ...

  8. DSP using MATLAB 示例 Example3.19

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...

  9. DSP using MATLAB示例Example3.18

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fou ...

  10. DSP using MATLAB 示例 Example3.11

    用到的性质 上代码: n = -5:10; x = rand(1,length(n)); k = -100:100; w = (pi/100)*k; % freqency between -pi an ...

随机推荐

  1. 大喜python版opencv3发布,demo脚本抢鲜版发布

    大喜,python版opencv3发布 zwPython3的升级也可以启动了,一直在等这个,zwPython会直接升级到版本3:zwPython3 zwPython3采用64位python3,支持op ...

  2. 892. Surface Area of 3D Shapes

    问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求这个3D多边形的表面积. Input: [[1,2],[3,4]] Output: 34 思路 只要 ...

  3. C++ Primer 5th Edition自学笔记(1)

    好吧,第一次写东西...如何下手呢...(请无视) -------------------------------------------------------------- Chapter 1. ...

  4. Android项目开发第四周学习总结

    Android项目开发实战第四周 在本周,我们进行了Android项目第四周的项目开发,在本周,我们对原有的项目进行改进,我们的想法是使项目在原有的基础上增加一些新的功能,使得txt阅读器可以更加先进 ...

  5. git clone,push,pull,fetch命令详解

    源自 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌 ...

  6. try catch finally return

    public override bool Start(IServerConfig config) { bool flag = true; listenSocket = new Socket(Liste ...

  7. NOIP 2018退役祭

    Day 0 实在是没啥特别想干的...路上看了一下FE的小玉的第四周目的视频...然后到了之后整理了一下东西,然后被slr教着学了一下一个叫翻棋的东西,然后立刻就上瘾了...然后就听slr先生教我滑铁 ...

  8. HDU 4745 Two Rabbits(最长回文子序列)

    http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有一个环,现在有两只兔子各从一个点开始起跳,一个沿顺时针,另一个沿逆时针,只能在一圈之内跳,并且每 ...

  9. POJ 1061 青蛙的约会(扩展欧几里得算法)

    http://poj.org/problem?id=1061 思路: 搞懂这个扩展欧几里得算法花了不少时间,数论真的是难啊. 含义:找出一对整数,使得ax+by=gcd(a,b). 接下来看这道题目, ...

  10. ssh connection refused

    执行sudo apt-get install openssh-server命令安装SSH服务