www.gusucode.com > signal 案例源码程序 matlab代码 > signal/UpsamplingImagingArtifactsExample.m

    %% Upsampling — Imaging Artifacts
% This example shows how to upsample a signal and how upsampling can result
% in images. Upsampling a signal contracts the spectrum. For example,
% upsampling a signal by 2 results in a contraction of the spectrum by a
% factor of 2. Because the spectrum of a discrete-time signal is
% $2\pi$-periodic, contraction can cause replicas of the spectrum normally
% outside of the baseband to appear inside the interval $[-\pi,\pi]$.

%%
% Create a discrete-time signal whose baseband spectral support is
% $[-\pi,\pi]$. Plot the magnitude spectrum.

F = [0 0.250 0.500 0.7500 1];
A = [1.0000 0.5000 0 0 0];
Order = 511;
B = fir2(Order,F,A);
[Hx,W] = freqz(B,1,8192,'whole');
Hx = [Hx(4098:end) ; Hx(1:4097)];
omega = -pi+(2*pi/8192):(2*pi)/8192:pi;

plot(omega,abs(Hx))

%%
% Upsample the signal by 2. Plot the spectrum of the upsampled signal.

y = upsample(B,2);
[Hy,W] = freqz(y,1,8192,'whole');
Hy = [Hy(4098:end) ; Hy(1:4097)];

hold on
plot(omega,abs(Hy),'r','linewidth',2)
xlim([-pi pi])
legend('Original Signal','Upsampled Signal')
xlabel('Radians/Sample')
ylabel('Magnitude')
text(-2,0.5,'\leftarrow Imaging','HorizontalAlignment','center')
text(2,0.5,'Imaging \rightarrow','HorizontalAlignment','center')
hold off

%%
% You can see in the preceding figure that the contraction of the spectrum
% has drawn subsequent periods of the spectrum into the interval
% $[-\pi,\pi]$.