Digital Signal Processing Reference
In-Depth Information
Solution:
a. The number of data points is
D f ¼ 8; 000
f s
N ¼
¼ 1; 000
8
There is no zero padding needed if we use the DFT formula. The detailed implementation is given in Program 4.1.
The first and second plots in Figure 4.12 show the two-sided amplitude and power spectra, respectively, using the
DFT, where each frequency counterpart at 7,000 Hz appears. The third and fourth plots are the one-sided
amplitude and power spectra, where the true frequency contents are displayed from 0 Hz to the Nyquist frequency
of 4 kHz (folding frequency).
b. If the FFT is used, the number of data points must be a power of 2. Hence we choose
N ¼ 2 10 ¼ 1; 024
Assuming there are only 1,000 data samples available in (a), we need to pad 24 zeros to the original 1,000
data samples before applying the FFT algorithm, as required. Thus the calculated frequency resolution is
D f ¼ f s =N ¼ 8; 000=1; 024 ¼ 7:8125 Hz. Note that this is an interpolated frequency resolution by using zero
padding. The zero padding actually interpolates a signal spectrum and carries no additional frequency information.
Figure 4.13 shows the spectral plots using FFT. The detailed implementation is given in Program 4.1.
Program 4.1. MATLAB program for Example 4.8.
% Example 4.8
close all;clear all
% Generate the sine wave sequence
fs ¼ 8000;
% Sampling rate
N ¼ 1000;
% Number of data points
x ¼ 2*sin(2000*pi*[0:1:N-1]/fs);
% Apply the DFT algorithm
figure(1)
xf ¼ abs(fft(x))/N;
% Compute the amplitude spectrum
P ¼ xf.*xf;
% Compute power spectrum
f ¼ [0:1:N-1]*fs/N;
% Map the frequency bin to frequency (Hz)
subplot(2,1,1); plot(f,xf);grid
xlabel( ' Frequency (Hz) ' ); ylabel( ' Amplitude spectrum (DFT) ' );
subplot(2,1,2);plot(f,P);grid
xlabel(
Frequency (Hz)
); ylabel(
Power spectrum (DFT)
);
'
'
'
'
figure(2)
% Convert it to one side spectrum
xf(2:N)
¼
2*xf(2:N);
% Get the single-side spectrum
P
¼
xf.*xf;
% Calculate the power spectrum
f
¼
[0:1:N/2]*fs/N
% Frequencies up to the folding frequency
subplot(2,1,1); plot(f,xf(1:N/2
þ
1));grid
xlabel(
Frequency (Hz)
); ylabel(
Amplitude spectrum (DFT)
);
'
'
'
'
subplot(2,1,2);plot(f,P(1:N/2 þ 1));grid
xlabel( ' Frequency (Hz) ' ); ylabel( ' Power spectrum (DFT) ' );
figure (3)
% Zero padding to the length of 1024
x ¼ [x,zeros(1,23)];
N ¼ length(x);
xf ¼ abs(fft(x))/N;
% Compute amplitude spectrum with zero padding
P ¼ xf.*xf;
% Compute power spectrum
f ¼ [0:1:N-1]*fs/N;
% Map frequency bin to frequency (Hz)
subplot(2,1,1); plot(f,xf);grid
Search WWH ::




Custom Search