Matlab
Processing
P. Professorson
UT Arlington Night School
MATLAB for Audio Signal
Processing
●
Getting real world data into your computer
●
Analysis based on frequency content
–
●
Fourier analysis
Modifying the spectrum
–
Filtering signal bands
●
●
●
FIR filters
IIR filters
Other stuff
Getting data into the computer
MicrophoneAnti-Aliasing
filter
Continuous
Sample &
Hold
Analog to
Digital
converter
DSP
system
Discrete
(fixed bits per sample)
Analog
Digital
Aliasing
●
Sampling frequency must be high enough to
characterize the signal correctly.
–
●
Fs >= 2 fmax
For a given Fs, signal components higher
than Fs/2 (Nyquist frequency) are forcibly
removed using ananti-aliasing filter prior to
sampling.
Blue signal : 5 Hz
Red signal : 30 Hz
Sampling frequency : 80 Hz
Nyquist frequency : 40 Hz
No aliasing in either signal.
Sampling frequency : 40 Hz
No aliasing in blue signal.
Nyquist frequency : 20 Hz
Aliasing in red signal. The 30
Hz signal manifests itself as a
10 Hz signal in the sampled
system.
Audio signals
●
Audio spectrum for music liesbetween 20Hz
to 20KHz
●
This gives a Nyquist sampling rate of 40KHz
●
CD audio uses a sampling rate of 44.1 KHz
●
16 bits per sample
●
WAV files store uncompressed samples
●
MP3 files store compressed data
Importing audio in MATLAB
●
WAV files:
–
–
sr: sampling rate
–
nbits: number of bits per sample
–
For mono audio, data is a vectorcontaining
audio samples
–
●
[data sr nbits] = wavread('song.wav');
For stereo audio, data is a 2-D vector
MP3 files – convert them to WAV format using
an external MP3 decoder, then use wavread
Playing back your audio
●
Create an audioplayer object
–
●
ap = audioplayer(data, sr);
Play the audio file using the object just
created
–
play(ap);
●
●
–
Thisplays the audio in the background while
the rest of your scrip continues working.
isplaying(ap) returns 1 if the file is still playing,
and 0 if the file has finished playback.
playblocking(ap);
●
This halts execution till the audio clip stops
playing
Audio spectrum
●
Human ear's response is non-linear. It is good
at discriminating low frequencies, but not so
good atdistinguishing between higher
frequencies.
●
Spectrum analyzers on music players have
logarithmic frequency scales.
●
Octave is a frequency scale that doubles at
every level.
–
F1 = 30Hz, F2 = 60Hz, F3 = 120Hz …
Discrete-time Fourier Analysis
●
Discrete Fourier Transform gives a discretefrequency representation of a discrete time
signal.
●
An N-point DFT of a signal willproduce N
numbers, each representing the signal
content at uniformly spaced frequencies
between - Fs/2 to + Fs/2 (not in that order).
●
Fast Fourier Transform (FFT) is a (class of)
algorithm(s) that produce the DFT efficiently
- O(N*log(N)) vs O(N2) for regular DFT.
MATLAB's FFT
●
f = fft(signal, N);
–
Produces N-point DFT of a signal
–
N should be > length of signal topreserve
fidelity, preferably a power of 2 for efficiency
●
For a real signal, f is generally complex. Its
absolute value is used to specify its
strength.
●
signal2 = ifft(f, M)
–
Reproduces a signal of length M whose Npoint DFT is specified in f
FFT fun facts
●
f = fft(signal, N);
–
f(1) is the DC component / signal average
●
Useless with respect to audio spectrum–
f(2) is the strength at frequency Fs/N
–
f(k) is the strength at frequency (k-1)*Fs/N
–
f(N/2+1) is the strength at Nyquist frequency Fs/2
●
Useless as it varies with phase of the signal
–
–
f needs to be scaled as f*2/N
–
●
Beyond this are negative frequencies which are mirror
images of positive frequencies (for real signals)
FFT bins represent the...
Regístrate para leer el documento completo.