|
|
|
|
Send Page To a Friend

|
M-Pack
1: WAV file processing: MATLAB function reference
|
| Version 1.2 |
Requires MATLAB
6.0 (R12) or later |
|
|
|
Adds
dither to the input data in preparation for (re-)quantisation.
Supports a variety of standard dithering methods including
noise-shaping with a user-specified custom FIR shaping
filter.
Implements
exactly the same dither methods as provided in the
wavout
function. However, no quantization is performed after
adding the dither, thereby leaving the user with the
flexibility in the choice of quantization method (by
contrast, the wavout
function always applies PCM quantization directly
after the dither, then writes the results to a WAV
file). |
|
| File
format: |
m-file |
|
Editable
source code:
|
yes
|
| Utilises
non-editable functions: |
no |
|
Platform:
|
PC/Windows
|
| Required
MATLAB Toolboxes: |
none
(except core MATLAB) |
| Demo
version limitations: |
p-code
only (non-editable); 2000 sample length limit (then
silence) |
|
|
|
|
|
|
|
| Inputs: |
| x |
matrix of input data. For example, if x is read from
a WAV file using wavin,
then the dimensions will be (Number of samples * Number
of Channels). It is assumed that the input data is
within the floating-point range -1:+1 (i.e. for correct
computation of dither amplitude).
|
| bits |
a structure containing the following fields:
-
QuantizationBits field (i.e. bits.QuantizationBits):
quantization bit-depth for determining the dither
amplitude [default value of 16]
- DitherMethod
field (i.e. bits.DitherMethod): numerical value
indicating which type of dithering method is applied
before quantisation. Possible values are:
- 0:
no dither
- 1:
rectangular PDF dither, with a peak-to-peak
amplitude of 1*LSB
- 2:
[default] triangular PDF dither, with a peak-to-peak
amplitude of 2*LSB
- 3:
triangular PDF with first-order high-pass noise
shaping
- 4:
triangular PDF with custom FIR noise shaping
filter
- DitherGain
field (i.e. bits.DitherGain): gain applied to amplitude
of dither [default value of 1] i.e. rectangular
PDF dither has amplitude of LSB*DitherGain, and
triangular PDF dither has amplitude of 2*LSB*DitherGain.
- NoiseShapeGain
field: (i.e. bits.NoiseShapeGain): gain applied
to the feedback path in the case where where noise
shaping is activated (i.e. for DitherMethod values
greater than 2) [default value of 1]
- NoiseShapeFIR
field: (i.e. bits.NoiseShapeFIR): vector of coefficients
for custom noise shaping filter (only valid for
DitherMethod = 4). An arbitrary filter of any order
may be specified. Default value is the following
fifth order filter: [2.033 -2.165 1.959 -1.590 0.6149]
taken from ref [1] p 851 (note:
designed for 44.1 kHz).
|
|
| Output: |
| y |
matrix of output data with dither applied. Note: clipping
is applied post-dither to prevent the data from exceeding
the range -1:+1.
|
|
|
|
|
See
the M-Pack 1 overview
for a detailed discussion of the dithering and noise-shaping
techniques used in this m-function.
Ref[1]:
"Minimally Audible Noise Shaping", Stanley P. Lipshitz,
John Vanderkooy, and Robert A. Wannamaker, J. Audio
Eng. Soc., Vol. 39, No. 11, November 1991.
|
|
|
|
| |
wavout
|
WAV
file writing (including quantization and dither) |
|
|
|
|
For a practical audible demonstration of the applications
of dither, refer to the examples
section of the wavout
help page.
The
following examples illustrate the
usage of the audiodither
function (and
in doing so, serves to demonstrate graphically
the effects of dither). All the code samples can be
found in the test script xmplaudiodither.m.
For
the purposes of demonstration, a low-level signal
(i.e. with an amplitude comparable with the quantization
step size) is preferable. Namely,
consider the following sinusoidal test signal, x,
with a peak-to-peak amplitude of 6 LSB (where 1 LSB
corresponds to the quantization step size):
|
| |
w=8;
%e.g. 8-bit
quantization(can
be arbitrary, the results scale accordingly) |
| |
Q=1/(pow2(1,w-1)-0.5);
%quantization
step size (i.e. LSB) |
| |
%Generate
the test signal with amplitude comparable with Q |
| |
x=3*Q*sin(10*pi*(0:(1/1000):1)');
%amplitude
[-3Q:+3Q] |
| |
|
| Now,
for reference, quantize the signal without dither
(assuming the "midriser" model for the quantizer,
see the M-Pack 1 overview): |
| |
y0=Q*floor(x/Q)+Q/2; |
| |
e0=x-y0;
%quantization
error |
| |
|
| Now,
apply 1 LSB peak-to-peak rectangular dither (using the
audiodither
command), then quantize: |
| |
bits.QuantizationBits=w;
|
| |
bits.DitherMethod=1; |
| |
y1=audiodither(x,bits); |
| |
y1=Q*floor(y1/Q)+Q/2;
%"midriser"
quantization |
| |
e1=x-y1;
%quantization
error |
| |
|
| Same
again, but this time using 2 LSB peak-to-peak triangular
dither: |
| |
bits.DitherMethod=2; |
| |
y2=audiodither(x,bits); |
| |
y2=Q*floor(y2/Q)+Q/2;
%"midriser"
quantization |
| |
e2=x-y2;
%quantization
error |
| |
|
| Same
again, but this time using 2 LSB peak-to-peak triangular
dither with highpass noise-shaping: |
| |
bits.DitherMethod=3; |
| |
y3=audiodither(x,bits); |
| |
y3=Q*floor(y3/Q)+Q/2;
%"midriser"
quantization |
| |
e3=x-y3;
%quantization
error |
| |
|
| Same
again, but this time using 2 LSB peak-to-peak triangular
dither with 5-coefficient FIR noise-shaping (default
filter design for DitherMethod
4): |
| |
bits.DitherMethod=4; |
| |
y4=audiodither(x,bits); |
| |
y4=Q*floor(y4/Q)+Q/2;
%"midriser"
quantization |
| |
e4=x-y4;
%quantization
error |
| |
|
| The
figure below compares the results of the above computations,
one plot per dither method. Each plot compares the original
unquantized signal (blue curve) with the quantization
error (green curve) associated with the given type of
dithering. All signal and error amplitudes are normalized
in units of LSB (this means that the plots are independent
of bit resolution or quantization step size). Examine
the xmplaudiodither.m
for
details on generating the plots. |
| |
|
 |
| |
|
|
The
top plot shows the undithered case. The quantization
error is clearly seen to be strongly correlated with
the signal in a nonlinear manner. This modulation
of the quantization noise by the signal leads to highly
undesirable audible distortion. The purpose of the
dither is to reduce this distortion.
The
second and third plots (from the top) show the beneficial
effect of additive rectangular and triangular dither,
respectively. The correlation between the signal and
the noise has been reduced in both cases, though at
the expense of added background noise. The suppression
of the nonlinear modulation is generally desirable
(from an auditory point of view), even at the expense
of the additional noise. The choice between rectangular
and triangular dither depends on the signal bandwidth
and the sample rate. In most applications, triangular
dither is preferable.
The
fourth and fifth plots (from the top) show the effect
of first-order highpass and of 5-coefficient
FIR feedback noise-shaped dither, respectively. The
added background noise is noticeably greater, especially
for the 5-coefficient FIR noise-shaper (lowest plot,
noting that the y-axis scale is greater). However,
as explained in the M-Pack
1 overview, this is to be expected. The point
is that even though the actual noise level is higher,
the perceived noise will be lower, assuming
that the noise-shaping filter is designed such as
to shift the quantization noise into the region of
the spectrum where the human hearing is at its least
sensitive. Refer
to the examples
section of the wavout
help page for an audio demonstration of the effectiveness
of noise-shaping in a "real-world" example.
|
|

Send Page To a Friend
|
|