Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Basic Digital Audio Signal Processing

In this section we look at some basic aspects of Digital Audio Signal


Processing:
93
• Some basic definitions and principles
• Filtering
• Basic Digital Audio Effects

JJ
II
J
I
Back
Close
Simple Waveforms

94

• Frequency is the number of cycles per second and is measured in


Hertz (Hz)
• Wavelength is inversely proportional to frequency JJ
1 II
i.e. Wavelength varies as f requency J
I
Back
Close
Simple Digital Audio Effects Example
Over the next few slides consider the following example:
1 1
fs = T fs = T

95

x(t) ADC x(n) DAFX y(n) DAC y(t)

×
e.g. 0.5

T
-> <-

JJ
II
J
I
Back
Close
Sample Interval and Sample Frequency
• An analog signal, x(t) with signal amplitude continuous over
time, t.
• Following ADC the signal is converted into a a 96

discrete-time and quantised amplitude signal, x(n) — a stream


of samples over discrete time index, n
– The time distance between two consecutive samples, the
sample interval, T (or sampling period).
– The the sampling frequency is fs = T1 — the number of samples
per second measured in Hertz (Hz).
• Next we apply some simple ADC — E.g here we
multiply the signal by a factor of 1.5 to produce y(n) = 0.5.x(n). JJ
• The signal y(n) is then forwarded to the DAC which reconstruct II
an analog signal y(t) J
I
Back
Close
The Sine Wave and Sound

97

The general form of the sine wave we shall use (quite a lot of) is as
follows:
y = A.sin(2π.n.Fw /Fs)
where:

A is the amplitude of the wave, JJ


Fw is the frequency of the wave, II
Fs is the sample frequency, J
n is the sample index. I
MATLAB function: sin() used — works in radians Back
Close
Cosine, Square and Sawtooth Waveforms
MATLAB functions cos() (cosine), square() and sawtooth()
similar.
98

JJ
II
J
I
Back
Close
The Decibel (dB)
When referring to measurements of power or intensity, we express
these in decibels (dB):
  99
X
XdB = 10 log10
X0
where:
• X is the actual value of the quantity being measured,
• X0 is a specified or implied reference level,
• XdB is the quantity expressed in units of decibels, relative to X0.
• X and X0 must have the same dimensions — they must measure
the same type of quantity in the the same units. JJ
II
• The reference level itself is always at 0 dB — as shown by setting J
X = X0 (note: log10(1) = 0). I
Back
Close
Why Use Decibel Scales?
• When there is a large range in frequency or magnitude, logarithm
units often used.
• If X is greater than X0 then XdB is positive (Power Increase)
• If X is less than X0 then XdB is negative (Power decrease). 100

• Power Magnitude = |X(i)|2| so (with respect to reference level)

XdB = 10 log10(|X(i)2|)
= 20 log10(|X(i)|)

which is an expression of dB we often come across.

JJ
II
J
I
Back
Close
Decibel and acoustics
• dB is commonly used to quantify sound levels relative to some 0
dB reference.
• The reference level is typically set at the 101

threshold of human perception


• Human ear is capable of detecting a very large range of sound
pressures (see later).

JJ
II
J
I
Back
Close
Examples of dB measurement in Sound
Threshold of Pain : The ratio of sound pressure that causes
permanent damage from short exposure to the limit that
(undamaged) ears can hear is above a million: 102

• The ratio of the maximum power to the minimum power is


above one (short scale) trillion (1012 ).
• The log of a trillion is 12, so this ratio represents a difference
of 120 dB.
Speech Sensitivity : Human ear is not equally sensitive to all the
frequencies of sound within the entire spectrum (see later):
• Noise levels at maximum human sensitivity — between 2 and
4 kHz (Speech) are factored more heavily into sound JJ
descriptions using a process called frequency weighting. II
J
I
Back
Close
Examples of dB measurement in Sound (cont.)
6dB per bit : In digital audio sample representation (linear pulse-code
modulation (PCM)),
• The first bit (least significant bit, or LSB) produces residual
quantization noise (bearing little resemblance to the source 103
signal)
• Each subsequent bit offered by the system doubles the
resolution, corresponding to a 6 (= 10 ∗ log10 (4)) dB.
• So a 16-bit (linear) audio format offers 15 bits beyond the first,
for a dynamic range (between quantization noise and clipping)
of (15 x 6) = 90 dB, meaning that the maximum signal is 90 dB
above the theoretical peak(s) of
quantisation noise.
• 8-bit linear PCM similarly gives (7 x 6) = 42 dB. JJ
• 48 dB difference between 8- and 16-bit which is (48/6 (dB)) II
8 times as noisy. J
I
Back
Close
Signal to Noise
Signal-to-noise ratio is a term for the power ratio between a signal
(meaningful information) and the background noise:
 2 104
Psignal Asignal
SN R = =
Pnoise Anoise
where P is average power and A is RMS amplitude.
• Both signal and noise power (or amplitude) must be measured at
the same or equivalent points in a system, and within the same
system bandwidth.
Because many signals have a very wide dynamic range, SNRs are
usually expressed in terms of the logarithmic decibel scale: JJ
    II
Psignal Asignal J
SN RdB = 10 log10 = 20 log10
Pnoise Anoise I
Back
Close
Digital Systems:
Representation and Definitions
Recall this Figure:
fs = 1
fs = 1 105
T T

x(t) ADC x(n) DAFX y(n) DAC y(t)

A digital system is represented by an algorithm which uses the


input signal x(n) as a sequence/stream of numbers and performs
operations upon the input signal to produce and output
sequence/stream of numbers — the output signal y(n).
JJ
II
• i.e. the DAFX block in the above figure. J
I
Back
Close
Classifying a Digital System:
Block v. sample-by-sample processing
We can classify the way a digital system processes the data in two 106

ways:
• Block v. sample-by-sample processing
Block processing : data is transferred into a memory buffer and
then processed each time the buffer is filled with new data.

E.g. fast Fourier transforms (FFT), Discrete Cosine Transform


(DCT), convolution — more soon

JJ
Sample-by-sample processing : input is processed on individual
II
sample data.
J
I
E.g. volume control, envelope shaping, ring modulation. Back
Close
Linear v. Non-linear Time Invariant Systems
A second means of classification:
Linear time invariant system (LTI) : Systems that do not change
behaviour over time and satisfy the superposition theory. The 107

output signal is signal changed in amplitude and phase.


I.e. A sine wave is still a sine wave just modified in amplitude
and/or phase
E.g. Convolution, Filters
Non-linear time invariant system : Systems whose output is strongly
shaped by non-linear processing that introduces harmonic
distortion — i.e. harmonics that are not present in the original
signal will be contained in the output.
I.e. if a sine wave is input the output may be a modified waveform JJ
or a sum of sine waves (see Fourier Theory later) whose frequencies II
may not be directly related to the input wave. J
E.g. Limiters, Compressors, Exciters, Distortion, Enhancers. I
Back
Close
Linear Time Invariant Systems

Linear time invariant system are classified by the relation to their


input/output functions, these are based on the following terms, 108
definitions and representations:

• Impulse Response and discrete convolution


• Algorithms and signal flow graphs

JJ
II
J
I
Back
Close
Impulse Response: Unit Impulse
Unit Impulse:

109
• A very useful test signal for digital systems
• Defined as:

1 if n = 0
δ(n) =
0 otherwise (n 6= 0)

JJ
II
J
I
Back
Close
Impulse Response Definition
If we apply a unit sample (impulse) function to a digital system we
get an output signal y(n) = h(n) 110
• h(n) is called the impulse response of the digital system.

x(n) = δ(n) h(n) y(n) = h(n)

JJ
II
J
I
Back
Close
Impulse Response: Discrete Convolution
If we know the impulse response h(n) of digital system we can
calculate the output signal y(n) for a given x(n) by the discrete
convolution formula: 111


X
y(n) = x(k).h(n − k) = x(n) ∗ h(n)
k=−∞

• This is usually denoted as y(n) = x(n) ∗ h(n)


• Computationally this usually computing using the fast
convolution method using the fast Fourier transform — more
soon
JJ
• MATLAB y = conv(x,h) function performs this task. II
• Convolution has many DSP applications including denoising, J
deblurring and reverb — more soon. I
Back
Close
Representation: Algorithms and Signal
Flow Graphs
112
It is common to represent digital system signal processing routines
as a visual signal flow graphs.

We use a simple equation relation to describe the algorithm.

We will need to consider three representations:


• Delay
• Multiplication
• Summation JJ
II
J
I
Back
Close
Signal Flow Graphs: Delay

• We represent a delay of one sampling interval by a block with a


113
T label:

x(n) T y(n) = x(n − 1)

• We describe the algorithm via the equation: y(n) = x(n − 1)

JJ
II
J
I
Back
Close
Signal Flow Graphs: Delay Example
A delay of the input signal by two sampling intervals:
• We can describe the algorithm by:
114
y(n) = x(n − 2)

• We can use the block diagram to represent the signal flow graph
as:
x(n) T y(n) = x(n − 1) T y(n) = x(n − 2)

JJ
II
x(n) y(n) = x(n − 2) J
I
Back
Close
Signal Flow Graphs: Multiplication

• We represent a multiplication or weighting of the input signal by


a circle with a × label. 115

• We describe the algorithm via the equation: y(n) = a.x(n)


a

x(n) × y(n) = a.x(n)

e.g. a = 0.5

JJ
II
J
I
x(n) y(n) = 0.5x(n)
Back
Close
Signal Flow Graphs: Addition

• We represent a addition of two input signal by a circle with a +


label. 116

• We describe the algorithm via the equation:


y(n) = a1.x1(n) + a2.x2(n)

a1 .x1 (n)

+ y(n) = a1 .x1 (n) + a2 .x2 (n)


JJ
II
J
a2 .x2 (n) I
Back
Close
Signal Flow Graphs: Addition Example
In the example, set a1 = a2 = 1:
a1 .x1 (n)

+ y(n) = a1 .x1 (n) + a2 .x2 (n)


117

a2 .x2 (n)

x1(n) x2(n)
JJ
II
J
I
y(n) = x1(n) + x2(n) Back
Close
Signal Flow Graphs: Complete Example
We can combine all above algorithms to build up more complex
algorithms:
1 1 1
y(n) = x(n) + x(n − 1) + x(n − 2)
2 3 4 118

• This has the following signal flow graph:

x(n − 1)
x(n) T T x(n − 2)

1 1 1
× 2 × 3 × 4

JJ
+ II
J
I
y(n) = 12 x(n) + 31 x(n − 1) + 41 x(n − 2)
Back
Close
Signal Flow Graphs: Complete Example Impulse Response
x(n − 1)
x(n) T T x(n − 2)

1 1 1
× 2 × 3 × 4
119

y(n) = 12 x(n) + 31 x(n − 1) + 41 x(n − 2)

JJ
II
J
I
x(n) y(n) = 21 x(n) + 13 x(n − 1) + 14 x(n − 2)
Back
Close
Transfer Function and Frequency Response
In a similar way to measuring the time domain impulse response
h(n) of a digital system we can measure the frequency domain
response. 120

• We can measure this by an impulse response

The frequency domain behaviour of digital systems reflects the


systems ability to:
• Pass,
• Reject, and
• Enhance
JJ
certain frequencies in the input signal frequency spectrum. II
J
We describe such behaviour with a transfer function H(z) and the I
frequency response H(f ) of the digital system. Back
Close
The Z-Transform and Fourier Transform
We need some means to obtain, H(z) and H(f ).

The Z-Transform is defined as: 121



X
X(z) = x(n).z −n
n=−∞
.

The Fourier Transform is defined as:


X
X(eiΩ) = x(n).e−iΩn where Ω = 2πf /fs
n=−∞
JJ
II
Clearly both transforms are related by substitution of z ↔ eiΩ J
I
Note: Will study the Fourier Transform in some detail very soon. Back
Close
Deriving The Transfer Function and
Frequency Response
Given an impulse response h(n) simply apply the Z-Transform:
122

X
H(z) = h(n).z −n
n=−∞

to get the transfer function H(z).

Similarly apply the Fourier Transform:



X
H(f ) = h(n).e−i2πf n/fs
n=−∞ JJ
II
to get the Frequency Response H(f ). J
I
Back
Close
Filtering

Filtering in a broad sense is selecting portion(s) of data for some


processing. 123

In many multimedia contexts this involves the removal of data


from a signal — This is essential in almost all aspects of lossy
multimedia data representations.

We will look at filtering in the frequency space very soon, but first
we consider Filtering via impulse responses.

We will look at:


JJ
IIR Systems : Infinite impulse response systems II
J
FIR Systems : Finite impulse response systems
I
Back
Close
Infinite Impulse Response (IIR) Systems
If h(n) is an infinite impulse response function then the digital
system is called and IIR system. 124

y(n)
x(n) +
Example:
• The algorithm is
represented by the T

difference equation:
× y(n − 1) = xH1 (n)

y(n) = x(n)−a1y(n−1)−a2y(n−2)
−a1 T
JJ
• This produces the opposite II
signal flow graph × y(n − 2) = xH2 (n) J
I
−a2
Back
Close
Infinite Impulse Response (IIR)Systems Explained

y(n)
The following happens: x(n) +
• The output signal y(n) is
fed back through a series of 125
delays T

• Each delay is weighted y(n − 1) = xH1 (n)


×
• Fed back weighted delay
summed and passed to −a1 T

new output.
• Such a feedback system is × y(n − 2) = xH2 (n)

called a recursive system


−a2
JJ
II
J
I
Back
Close
Z-transform of IIR

If we apply the Z-transform we get:


126

Y (z) = X(z) − a1z −1Y (z) − a2z −2Y (z)


X(z) = Y (z)(1 + a1z −1 + a2z −2)

Solving for Y (z)/X(z) gives H(z) our transfer function:

Y (z) 1
H(z) = =
X(z) 1 + a1z −1 + a2z −2
JJ
II
J
I
Back
Close
A Complete IIR System
x(n) x(n − 1) x(n − 2) x(n − N + 1)
T T T

127
× b0 × b1 × b2 × bN −2 × bN −1

y(n)
+ + + + +

× −aM × −aM −1 × −aM −2 × −a1

T T T
y(n − M ) y(n − 1)

JJ
Here we extend:
II
The input delay line up to N − 1 elements and
J
The output delay line by M elements.
I
Back
Close
Complete IIR System Algorithm
x(n) x(n − 1) x(n − 2) x(n − N + 1)
T T T

× b0 × b1 × b2 × bN −2 × bN −1
128
y(n)
+ + + + +

× −aM × −aM −1 × −aM −2 × −a1

T T T
y(n − M ) y(n − 1)

We can represent the IIR system algorithm by the difference


equation:
M
X N −1
X JJ
y(n) = − ak y(n − k) + bk x(n − k) II
k=1 k=0 J
I
Back
Close
Complete IIR system Transfer Function

The Z-transform of the difference equation is:


129
M
X N −1
X
Y (z) = − ak z −k Y (z) + bk z −k X(z)
k=1 k=0

and the resulting transfer function is:


PN −1 −k
k=0 bk z
H(z) = P M
1+ k=1 ak z −k

JJ
II
J
I
Back
Close
Filtering with IIR
We have two filter banks defined by vectors: A = {ak }, B = {bk }.

These can be applied in a sample-by-sample algorithm: 130

• MATLAB provides a generic filter(B,A,X) function which


filters the data in vector X with the filter described by vectors A
and B to create the filtered data Y.

The filter is of the standard difference equation form:


a(1) ∗ y(n) = b(1) ∗ x(n) + b(2) ∗ x(n − 1) + ... + b(nb + 1) ∗ x(n − nb)
−a(2) ∗ y(n − 1) − ... − a(na + 1) ∗ y(n − na)

• Filter banks can be created manually or MATLAB can provide JJ


some predefined filters — more later, see tutorials II
J
• See also help filter, online MATLAB docs and tutorials on I
filters.
Back
Close
Filtering with IIR: Simple Example
The MATLAB file IIRdemo.m sets up the filter banks as follows:
fg=4000;
fa=48000; 131
k=tan(pi*fg/fa);

b(1)=1/(1+sqrt(2)*k+kˆ2);
b(2)=-2/(1+sqrt(2)*k+kˆ2);
b(3)=1/(1+sqrt(2)*k+kˆ2);
a(1)=1;
a(2)=2*(kˆ2-1)/(1+sqrt(2)*k+kˆ2);
a(3)=(1-sqrt(2)*k+kˆ2)/(1+sqrt(2)*k+kˆ2);

and then applies the difference equation:


for n=1:N
y(n)=b(1)*x(n) + b(2)*xh1 + b(3)*xh2 - a(2)*yh1 - a(3)*yh2; JJ
xh2=xh1;xh1=x(n); II
yh2=yh1;yh1=y(n);
end; J
I
Back
Close
Filtering with IIR: Simple Example Output
This produces the following output:

0.5
132
x(n) →

−0.5

−1

0 2 4 6 8 10 12 14 16 18
n→

0.5
y(n) →

0
JJ
−0.5 II
−1 J
0 2 4 6 8 10 12 14 16 18 I
n→
Back
Close
Finite Impulse Response (FIR) Systems
FIR system’s are slightly simpler — there is no feedback loop.

y(n)
x(n) × + 133

b0
A simple FIR system can be
described as follows:
T
y(n) = b0 x(n) + b1 x(n − 1) + b2 x(n − 2)

x(n − 1) = xH1 (n) ×


• The input is fed through
delay elements
T b1
• Weighted sum of delays
give y(n) JJ
x(n − 2) = xH2 (n) × II
J
b2 I
Back
Close
Simple FIR Transfer Function

Applying the Z-transform we get:


134
Y (z) = b0X(z) + b1z −1X(z) + b2z −2X(z)

and we get the transfer function:

Y (z)
H(z) = = b0 + b1z −1 + b2z −2
X(z)

JJ
II
J
I
Back
Close
A Complete FIR System
To develop a more complete FIR system we need to add N −1 feed
forward delays:
x(n) x(n − 1) x(n − 2) x(n − N + 1) 135
T T T

× b0 × b1 × b2 × bN −2 × bN −1

y(n)
+ + + +

We can describe this with the algorithm:


N −1
X
y(n) = bk x(n − k) JJ
k=0 II
J
I
Back
Close
Complete FIR System
Impulse Response and Transfer Function
136
The FIR system has the finite impulse response given by:
N −1
X
h(n) = bk δ(n − k)
k=0

This means that each impulse of h(n) is a weighted shifted unit


impulse.

We can derive the transfer function as:


N −1
JJ
X II
H(z) = bk z −k J
k=0
I
Back
Close

You might also like