program_2_1.m

来自「数字信号处理—基于计算机的方法教材上的所有例题源程序」· M 代码 · 共 22 行

M
22
字号
% Program 2_1 for example 2.1
% Generation of the ensemble average
%
N = 50;     % The length of the signal
M = 20;     % The times of measurement
n = 0:N-1;  % The index of sinal
s = 2*n.*(0.9.^n); % Generate the uncorrupted signal
subplot(221);stem(n,s);xlabel('Time index n');ylabel('Amplitude'); title('Signal');
d = rand(N,1)-0.5; % Generate the random noise
x1 = s+d';
subplot(222);stem(n,d);xlabel('Time index n');ylabel('Amplitude'); title('Noise');
subplot(223);stem(n,x1);xlabel('Time index n');ylabel('Amplitude'); title('Noisy Signal');
for m = 1:M-1;        % average
    d = rand(N,1)-0.5;
    x = s + d';
    x1 = x1 + x;
end
x1 = x1/M;
subplot(224);h=stem(n,s);hold on;set(h,'MarkerFaceColor','red')
subplot(224);stem(n,x1);xlabel('Time index n');ylabel('Amplitude');
title('Comparison of original and averaged noisy signal');
legend('Original Signal','Averaged Noisy Signal',1);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?