《DSP using MATLAB》Problem 2.8

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;
运行结果:

牢记:
1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。

浙公网安备 33010602011771号