Академический Документы
Профессиональный Документы
Культура Документы
Lab Exercise -1
Primitive Signals
Example 1. Sine wave
The sine wave is more or less the building block of all signals, musical or not.
There is exactly one frequency present in a signal with one steady sine wave.
Three parameters, the frequency, the amplitude and the initial phase, characterize every steady sine
wave completely.
The Fourier transform can be used to inspect what kinds of sine waves there are in a signal.
fs = 44100;
t = 0:1/fs:0.001;
s = sin(2 * pi * 1700 * t);
subplot(211), stem(abs(fft(s))), title('abs(fft(s))')
subplot(212), stem(s), title('s')
1
Example 2. Noise
fs = 44100;
n = randn(fs, 1);
n = n / max(abs(n));
subplot(211)
plot(n), axis tight
subplot(212)
specgram(n)
Example 3. Speech
2
The following is the spectrogram of the above speech sound.
Example 4. Piano
The piano sample shown is the middle C, whose fundamental frequency is 261 Hz.
The piano sample is an example of a harmonic sound; this means that the sound consists of sine
waves which are integer multiples of the fundamental frequency. (Actually the piano is not
perfectly harmonic.)
You can listen to the piano sample.
3
The following is the spectrogram of the above piano sound, resampled to 16000 Hz sample rate. Here the
s2 = resample(s, 1, 3);
specgram(s2, 512, fs / 3);
colorbar
The snare drum sample doesn't have a fundamental frequency nor does it have overtones.
You can listen to the snare drum sample.
4
And here is the spectrogram of the snare drum hit, without resampling. Notice the lack of harmonic
content.
5
Manav Rachna University, Faridabad
Department of Electronics and Communication Engineering
Lab Exercise -2
Example 1
Linear Filters
There are broadly two kinds of digital linear filters: finite impulse response (FIR) and infinite
impulse response (IIR) filters.
Comparison of FIR vs. IIR filters:
FIR IIR
linear phase response possible yes No
overall frequency response control good Bad
nearly-"brickwall" response possible no Yes
efficiency (multiplications required) bad Good
Conclusion: in audio applications, when the phase response isn't critical, it is often profitable to
use IIR filters because of their efficiency.
The following spectrogram is as computed above, using 11.6 ms windows which overlap by 50%
the spectrum displayed below the spectrogram is taken at 0.2 seconds time
7
u = s(0.2 * fs:0.2 * fs + 511) .* hanning(512);
U = fft(u);
f = (0:256) / 256 * fs / 2;
plot(f, 20 * log10(abs(U(1:257))))
axis tight,grid on
xlabel('frequency [Hz]')
ylabel('amplitude [dB]')
Example 3. Windowing
short-time signal processing is practically always done using windowing
in short-time signal processing, signals are cut into small pieces called frames, which are processed
one at a time
frames are windowed with a window function in order to improve the frequency-domain
representation
what windowing essentially means is multiplying the signal frame with the window function point-
by-point
8
[s, fs] = wavread('pia60.wav', [5000 6000]);
subplot(131)
plot(s(1:512))
title('s(1:512)'), axis tight, grid on
subplot(132)
plot(hanning(512),'r')
title('hanning(512)'), axis tight, grid on
subplot(133)
plot(s(1:512) .* hanning(512))
title('s(1:512) .* hanning(512)'), axis tight, grid on
S1 = fft(s(1:512));
S2 = fft(s(1:512) .* hanning(512));
f = (0:256) / 256 * fs / 2;
plot(f, 20 * log10(abs(S1(1:257))))
hold on
plot(f, 20 * log10(abs(S2(1:257))), 'r')
axis tight,grid on
xlabel('frequency [Hz]')
ylabel('amplitude [dB]')
9
Example 5. Correlation
the cross-correlation between two signals tells how `identical' the signals are
in other words, if there is correlation between the signals, then the signals are more or less
dependant on each other
for example, the correlation between two sine waves with different periods is zero
t = 0:1/fs:0.2;
a = 2 * sin(2 * pi * 20 * t);
b = 2 * sin(2 * pi * 30 * t);
ep(a, b)
sum(a .* b)
ans =
-4.7622e-12
normally the correlation value is computed with different alignments, called lags, between the
signals
the correlation value is computed between a[n] and b[n - l], a[n] and b[n - l + 1], a[n] and b[n - l +
2], ..., a[n] and b[n - 1], a[n] and b[n], a[n] and b[n + 1], ..., a[n] and b[n + l - 1] and finally
between a[n] and b[n + l]
i.e. the other signal is held static and the other signal is shifted one sample at a time and the
correlation value is computed every time
10
subplot(211)
n = randn(4000, 1);
[ac, l] = xcorr(n, n, 1000);
plot(l, ac), axis tight, grid on
title('gaussian noise autocorrelation')
subplot(212)
[s, fs] = wavread('pia60.wav');
[ac, l] = xcorr(s, s, 1000);
plot(l, ac), axis tight, grid on
title('piano autocorrelation')
fs = 44100;
f = 2 .^ (10 * rand(1, 6) + 4.2);
t = 0:1/fs:1;
for i = 1:length(f)
s = 0.2 * sin(2 * pi * f(i) * t);
wavwrite(s, fs, 16, ['sine' num2str(i) '.wav']);
end
here are 6 bandpass filtered versions of a piece of music: filter1, filter2, filter3, filter4, filter5,
filter6
what bandpass frequency belongs to which version: (a) 212 Hz, (b) 552 Hz, (c) 1300 Hz, (d) 1428
Hz, (e) 2676 Hz and (f) 6480 Hz
correct answers to the sine frequencies: 1-c (1364 Hz), 2-d (4539 Hz), 3-f (13954 Hz), 4-b (688
Hz), 5-e (8200 Hz) and 6-a (61 Hz)
correct answers to the filter bandpass frequencies: 1-e (2676 Hz), 2-b (552 Hz), 3-c (1300 Hz), 4-f
(6480 Hz), 5-d (1428 Hz) and 6-a (212 Hz)
References
Pohlmann, Ken, ``Principles of Digital Audio.'' 3rd Edition, ISBN 0-07-050468-7, McGraw-Hill,
Inc., 1995
Oppenheim, Alan V. and Schafer, Ronald W., ``Discrete-Time Signal Processing.''
Ifeachor and Jervis, ``Digital Signal Processing.''
12