Digital Signal Processing Reference
In-Depth Information
0
0
20
20
40
40
60
60
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.8
1
k (s)
k (s)
(a)
(b)
Fig. 17.5. Spectrograms of the
speech signal recorded in
testaudio1.wav .
(a) Narrow-band spectrogram;
(b) wide-band spectrogram.
sound are examples of non-stationary signals. Therefore, the techniques pre-
sented in Section 17.1 can also be used to estimate the spectral content of audio
signals.
To calculate the spectrogram of the audio signal stored in testaudio1.wav, we
use the following M ATLAB code:
>> %Reading the input audio file
>> infile = 'testaudio1.wav'; % audio file
>> [x, Fs, nbit] = wavread(infile); % x = signal
% Fs = sampling rate
% nbit = number of
% bits per sample
>> nfft = 1024; nwind = 1024; noverlap = 768;
>> [spgram,F,T] = specgram(x, nfft,Fs,hanning(nwind),
noverlap);
>> spgramdB = 20*log10 (abs (spgram) + eps);
>> imagesc([0 length (x)/Fs], 2*pi*F, spgrandB);
>> colormap(gray)
The above code calculates the spectrogram using a window size of 1024, shown
in Fig. 17.5(a). As the window size is a power of 2, we choose to calculate the
DFT without any zero padding. For the audio signal testaudio1.wav , the
sampling rate of the signal is given by 22 050 samples/s. A window size of
1024 samples therefore corresponds to a duration of 1024 / 22 050 = 0 . 0461 s.
Hence, the time resolution of the spectrogram is limited to 46 ms.
The frequency resolution in the spectrogram plotted in Fig. 17.5(a) is obtained
by dividing the sampling frequency by the total number of samples in the fre-
quency domain, which gives 22 050 / 1024 = 21 . 53 Hz. During the computation
of the spectrogram, it is possible to trade-off time resolution for the frequency
resolution, and vice versa. To improve the time resolution of the spectrogram
in Fig. 17.5(a), we decrease the window size to 256 with an overlap of 128
samples between two successive windows:
Search WWH ::




Custom Search