首页 > 其他 > 详细

《DSP using MATLAB》Problem 2.8

时间:2017-12-05 23:53:03      阅读:405      评论:0      收藏:0      [点我收藏+]

技术分享图片

1、代码:

从MATLAB官方网上下载的。

%*************************************************************************%
%A code for the Downsampler%
%Author: Yashwant Marathe%
%Date:20-12-2010%
function [y ny] = dnsample(x,n,M)
%x is a sequence over indices specified by vector n,M is the downsampling factor.

param=n/M;
%generates the parameter vector.This vector will decide which input samples will be present in the output.

samp=fix(param)==param;
%only those output vectors corresponding to indices where samp==1 will be present in the output.

y=x(samp==1);
%generates the output sequence

ny=n(samp==1)/M;
%generates the indices of the output sequence

end
%**************************************************************************

2、代码

%% ------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Problem 2.8.2 \n\n‘);

banner();
%% ------------------------------------------------------------------------

n = [-50:1:50]; 
x = sin( 0.125 * pi * n ); 

M = 4;

[y, m] = dnsample(x, n, M);


figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 2.8.2‘)
set(gcf,‘Color‘,[1,1,1])                  % 改变坐标外围背景颜色

subplot(2,1,1); stem(n, x); title(‘x sequence‘);
xlabel(‘n‘); ylabel(‘x(n)‘) ;
grid on
subplot(2,1,2); stem(m, y); title(‘y sequence‘);
xlabel(‘n‘); ylabel(‘y(m)‘);
grid on;

  运行结果:

技术分享图片

3、代码

%% ------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Problem 2.8.3 \n\n‘);

banner();
%% ------------------------------------------------------------------------

n = [-50:1:50]; 
x = sin( 0.5 * pi * n ); 

M = 4;

[y, m] = dnsample(x, n, M);


figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Problem 2.8.3‘)
set(gcf,‘Color‘,[1,1,1])                  % 改变坐标外围背景颜色

subplot(2,1,1); stem(n, x); title(‘x sequence‘);
xlabel(‘n‘); ylabel(‘x(n)‘) ;
grid on
subplot(2,1,2); stem(m, y); title(‘y sequence‘);
xlabel(‘n‘); ylabel(‘y(m)‘);
grid on;

  运行结果:

技术分享图片

 

《DSP using MATLAB》Problem 2.8

原文:http://www.cnblogs.com/ky027wh-sx/p/7990073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!