|
|
|
|
Send Page To a Friend

|
M-Pack
1: WAV file processing: MATLAB function reference
|
| Version 1.2 |
Requires MATLAB
6.0 (R12) or later |
|
|
|
Performs
sample rate conversion of the input data using optimised
hard-wired multi-stage FIR re-sampling filters. The
conversion ratio is determined by the ratio of the
specified output and input sample rates. The following
sample rates commonly used in digital audio are supported
(Hz): 8000, 11025, 16000, 22050, 32000, 44100, 48000,
96000, 192000. |
|
| File
format: |
mex-file
(dll) |
|
Editable
source code:
|
no
|
| Utilises
non-editable functions: |
no |
|
Platform:
|
PC/Windows
|
| Required
MATLAB Toolboxes: |
none
(except core MATLAB) |
| Demo
version limitations: |
50000
sample data length limit (then silence) |
|
|
|
| |
OutputData=
audioresample(InputData,InputFs,OutputFs); |
|
|
|
| Inputs: |
| InputData |
matrix of input data, one row per sample, one column
per channel
|
| InputFs |
sample rate of input data (in Hz) -- note this is
intended to be the actual sample rate at which the
input data was collected. However, any supported sample
rate may be used (i.e. whether it corresponds to the
actual sample rate or not). The supported input sample
rates are (in Hz): 8000, 11025, 16000, 22050, 32000,
44100, 48000, 96000, 192000
|
| OutputFs |
sample rate of output data (in Hz). Any of the following
supported sample rates may be used (in Hz): 8000,
11025, 16000, 22050, 32000, 44100, 48000, 96000, 192000.
NOTE: if the input sample rate and output sample rate
are the same, no conversion is applied (and the output
equals the input).
|
|
| Output: |
| OutputData |
matrix of output data, one row per sample, one column
per channel. The number of rows (samples) of the output
matrix differs from that of the input matrix, in accordance
with the sample rate conversion ratio. The numbers of
columns (channels) of the output matrix is the same
as that of the input matrix. |
|
|
|
|
This
function is suitable for resampling a single chunk
of data in the MATLAB workspace. It is similar to
the resample
function in the Signal Processing Toolbox (from The
MathWorks), though it does not have the same flexibility
to support arbitrary sample rates (i.e. beyond those
listed above).
An
alternative function, wavresample,
employs the same converters as audioresample,
but in a chunk-by-chunk mode so that the resampling
can be performed on arbitrarily large WAV files without
incurring excessive memory usage.
The
converters utilize hard-wired multi-stage FIR re-sampling
(anti-aliasing / anti-imaging) filters written directly
in C/C++ and implemented in MATLAB within a compiled
mex function (dll).
All
multi-stage filters have been designed to meet the
following low-pass composite specifications as applied
to the input-output data:
- passband
attenuation: <=0.01 dB;
- stopband
attenuation >=120 dB
where
the composite low-pass edge frequency is chosen in
accordance with the given conversion ratio (i.e. at
half the output sample rate for down-samplers to avoid
"aliasing", and at half the input sample
rate for up-samplers to avoid "imaging").
Any
delay introduced by the filtering is automatically
removed so there is no need to compensate for the
delay after issuing the audioresample
command.
For
efficiency, all filters in all stages have been implemented
in polyphase form.
See ref [1] for more information
on multi-stage sample rate conversion and polyphase
representation.
See
the M-Pack 1 overview
for detailed information on the multi-stage sample
rate converters used in this function.
Reference:
Ref[1]:"Multirate
Digital Signal Processing", Ronald E. Crochiere
and Lawrence R. Rabiner, Prentice-Hall, 1983.
|
|
|
|
|
|
|
|
| The
following examples are contained in the m-script file
entitled xmplaudioresample.m
First
generate a 1 kHz sinusoidal test signal at the nominal
sample rate of 44.1 kHz.
|
| |
y44=sin(2*pi*1000*(0:(1/44100):1)');
|
| |
| Ex.1 |
Convert
the sample rate of the 44.1 kHz test signal to 48 kHz; |
| |
y48=audioresample(y44,44100,48000); |
| |
|
| |
Plot
the results using time vectors appropriate to each sample
rate, noting the rather close match between the original
and resultant signals (as expected since a 1 kHz signal
should be unaffected by a sample rate conversion from
44.1 to 48 kHz): |
| |
t44=0:1/44100:0.005;
%time vector for 44.1 kHz |
| |
t48=0:1/48000:0.005;
%time vector |
| |
stairs(t44,y44(1:length(t44)));
hold; stairs(t48,y48(1:length(t48)),'r'); |
| |
|
 |
| |
| Ex.2 |
Now
convert the original sample rate from 44.1Khz to 8kHz
and plot the results, noting the preservation of the
1 kHz signal at the 8 kHz sample rate, albeit with increased
"graininess" associated with the lower sample
rate. Signal preservation is exected since 1 kHz is
still within the Nyquist rate of 4 kHz corresponding
to the new sample rate of 8 kHz. However, any original
signal above 4 kHz would be eliminated by the anti-alising
filters within audioresample. |
| |
| |
y8=audioresample(y44,44100,8000); |
| |
|
 |
| |
| Ex.3 |
"Roundtrip"
example. Convert the original sample rate from 44.1
kHz up to 192 kHz then back to 44.1 kHz and plot the
results, noting that, as expected, the 1 kHz signal
is effectively preserved since it is unaffected by sample
rate conversions well above its bandwidth: |
| |
| |
y192=audioresample(y44,44100,192000);
|
| |
y44_=audioresample(y192,192000,44100); |
| |
t44=0:1/44100:0.005;
|
| |
stairs(t44,y44(1:length(t44)));
hold stairs(t44,y44_(1:length(t44)),'r'); |
| |
|
 |
|

Send Page To a Friend
|
|