Audio Signal Processing Basics

Jarno Seppänen
27.5.1999
Audio Research Group
Tampere University of Technology
Signal Processing Laboratory


Glossary

There is a signal processing glossary on a page of its own.

For a more exhaustive list of English-Finnish translations, see the Audiosignaalinkäsittelyn sanasto by Vesa Välimäki.

Primitive Signals

Sine wave

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')

Noise

fs = 44100;
n = randn(fs, 1);
n = n / max(abs(n));
subplot(211)
plot(n), axis tight
subplot(212)
specgram(n)

Speech

[s, fs] = wavread('seiska.wav');
plot(s),axis tight,grid on

The following is the spectrogram of the above speech sound.

specgram(s, 512, fs);
colorbar

Piano

[s, fs] = wavread('pia60.wav');
plot(s),axis tight,grid on

The following is the spectrogram of the above piano sound, resampled to 16000 Hz sample rate. Here the overtones can be seen clearly.

s2 = resample(s, 1, 3);
specgram(s2, 512, fs / 3);
colorbar

Snare drum

[s, fs] = wavread('snareHit.wav');
plot(s),axis tight,grid on

And here is the spectrogram of the snare drum hit, without resampling. Notice the lack of harmonic content.

specgram(s, 512, fs);
colorbar

Linear Filters

fir_b = remez(30,[0 0.2 0.3 1], [1 1 0 0]);
[iir_b, iir_a] = butter(10, 0.2);
subplot(211)
impz(fir_b, 1, 41)
title('An FIR filter'), axis([0 40 -0.1 0.25]), grid on
subplot(212)
impz(iir_b, iir_a, 41)
title('An IIR filter'), axis([0 40 -0.1 0.25]), grid on

Time and Frequency Domains

[s, fs] = wavread('snareHit.wav');
subplot(211), plot(abs(fft(s))), title('abs(fft(s))')    
subplot(212), plot(s), title('s')
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]')

Windowing

[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]')

Correlation

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

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')

Frequency quiz

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
[s, fs] = wavread('helmi.wav');
f = 2 .^ (7 * rand(1, 6) + 6);
for i = 1:length(f)
  ff = [0.6 0.9 1.1 1.4] * f(i) * 2 / fs;
  ff = [0 ff 1];
  b = remez(300, ff, [0 0 1 1 0 0], [10 1 10]);
  freqz(b, 1, 512, fs); drawnow
  ss = 4 * filter(b, 1, s);
  wavwrite(ss, fs, 16, ['filter' num2str(i) '.wav']);
end

References




http://www.cs.tut.fi/sgn/arg/intro/
Last modified: Tue Jun 1 11:58:55 1999