《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;

  运行结果:

时间: 2024-10-11 14:14:55

《DSP using MATLAB》Problem 2.8的相关文章

《DSP using MATLAB》 Problem 2.3

本题主要是显示周期序列的. 1.代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.3.1 \

《DSP using MATLAB》Problem 2.5

2.代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.5.2 \n\n'); time_st

《DSP using MATLAB》Problem 2.6

1.代码 %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.6.1 \n\n'); [v, d] =

《DSP using MATLAB》Problem 2.14

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.14 \n\n'); banner();

《DSP using MATLAB》Problem 2.16

先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Prob

《DSP using MATLAB》Problem 2.15

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.15 \n\n'); banner();

《DSP using MATLAB》Problem 2.19

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.19 \n\n'); banner();

《DSP using MATLAB》Problem 2.20

代码: %% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 2.20 \n\n'); banner();

《DSP using MATLAB》Problem 3.1

先写DTFT子函数: function [X] = dtft(x, n, w) %% ------------------------------------------------------------------------ %% Computes DTFT (Discrete-Time Fourier Transform) %% of Finite-Duration Sequence %% Note: NOT the most elegant way % [X] = dtft(x, n,