Digital Signal Processing Reference
In-Depth Information
6
4
2
0
0
500
1000
1500
2000
2500
3000
3500
4000
Frequency (Hz)
6
4
2
0
0
200
400
600
800
1000
1200
1400
1600
1800
2000
Frequency (Hz)
FIGURE 12.3B
Spectrum before downsampling and spectrum after downsampling using the anti-aliasing filter.
% Generate 2048 samples
fs
¼
8000;
% Sampling rate
N
¼
2048;
% Number of samples
M
¼
2;
% Downsample factor
n
¼
0:1:N-1;
x
cos(5*n*pi/8);
% Compute single-sided amplitude spectrum
% AC component will be doubled, and DC component will be kept at the same value
X ¼ 2*abs(fft(x,N))/N;X(1) ¼ X(1)/2;
% Map the frequency index up to the folding frequency in Hz
f ¼ [0:1:N/2-1]*fs/N;
% Downsampling
y ¼ x(1:M:N);
NM ¼ length(y); % Length of the downsampled data
% Compute the single-sided amplitude spectrum for the downsampled signal
Y ¼ 2*abs(fft(y,NM))/length(y);Y(1) ¼ Y(1)/2;
% Map the frequency index to the frequency in Hz
fsM ¼ [0:1:NM/2-1]*(fs/M)/NM;
subplot(2,1,1);plot(f,X(1:1:N/2));grid; xlabel( ' Frequency (Hz) ' );
subplot(2,1,2);plot(fsM,Y(1:1:NM/2));grid; xlabel( ' Frequency (Hz) ' );
figure
¼
5*sin(n*pi/4)
þ
 
Search WWH ::




Custom Search