1. 程式人生 > >《DSP using MATLAB》示例9.2

《DSP using MATLAB》示例9.2

mage rpo bsp file sig pos 運行 paper 技術分享

技術分享

代碼:

%% ------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> Exameple 9.2 \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);
%% ------------------------------------------------------------------------

n = 0:2048; k1 = 256; k2 = k1+32; m = 0:(k2-k1);


%% -----------------------------------------------------------------
%%                             Plot
%% -----------------------------------------------------------------  
Hf1 = figure(‘units‘, ‘inches‘, ‘position‘, [1, 1, 9, 7], ...
	‘paperunits‘, ‘inches‘, ‘paperposition‘, [0, 0, 6, 4], ...
	‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Exameple 9.2‘);
set(gcf,‘Color‘,‘white‘); 

TF = 10;
% (a) Original signal
x = cos(0.125*pi*n); subplot(2, 2, 1); 
Ha = stem(m, x(m+k1+1), ‘g‘, ‘filled‘); axis([-1, 33, -1.1, 1.1]); grid on;
set(Ha, ‘markersize‘, 2); xlabel(‘n‘); ylabel(‘Amplitude‘); 
title(‘Original Sequence x(n)‘, ‘fontsize‘, TF);
set(gca, ‘xtick‘, [0, 16, 32]); 
set(gca, ‘ytick‘, [-1, 0, 1]);

% (b) Decimation by D = 2
D = 2; y = decimate(x, D); subplot(2, 2, 2); 
Hb = stem(m, y(m+k1/D+1), ‘c‘, ‘filled‘); axis([-1, 33, -1.1, 1.1]); grid on;
set(Hb, ‘markersize‘, 2); xlabel(‘n‘); ylabel(‘Amplitude‘);
title(‘Decimated by D = 2‘, ‘fontsize‘, TF);
set(gca, ‘xtick‘, [0, 16, 32]); 
set(gca, ‘ytick‘, [-1, 0, 1]);

% (c) Decimation by D = 4
D = 4; y = decimate(x, D); subplot(2, 2, 3); 
Hc = stem(m, y(m+k1/D+1), ‘r‘, ‘filled‘); axis([-1, 33, -1.1, 1.1]); grid on;
set(Hc, ‘markersize‘, 2); xlabel(‘n‘); ylabel(‘Amplitude‘);
title(‘Decimated by D = 4‘, ‘fontsize‘, TF);
set(gca, ‘xtick‘, [0, 16, 32]); 
set(gca, ‘ytick‘, [-1, 0, 1]);

% (d) Decimation by D = 8
D = 8; y = decimate(x, D); subplot(2, 2, 4); 
Hd = stem(m, y(m+k1/D+1), ‘m‘, ‘filled‘); axis([-1, 33, -1.1, 1.1]); grid on;
set(Hd, ‘markersize‘, 2); xlabel(‘n‘); ylabel(‘Amplitude‘);
title(‘Decimated by D = 8‘, ‘fontsize‘, TF);
set(gca, ‘xtick‘, [0, 16, 32]); 
set(gca, ‘ytick‘, [-1, 0, 1]);

  運行結果:

技術分享

我們將畫出信號的中間段,來避免默認低通濾波器的末端效應。默認低通采樣8階切比雪夫I型,截止頻率0.8π/D(本例子來說分別是0.4π、0.2π和0.1π三個截止頻率。)

從圖中看出,按D=2和D=4減采樣序列是正確的,在低采樣率情況下展示了原始正弦序列x(n);但是,D=8的序列幾乎為零,原因就是首先對輸入序列進行低通,然後再

減采樣。MATLAB中decimat函數使用低通的截止頻率為0.1π,原始信號0.125π幾乎消減沒了。

《DSP using MATLAB》示例9.2