Hi,
I have a quantized input audio signal file (.wav).
I want to convert the sampling rate from 11025 Hz to 24000.
I know that I have to upsample the signal, lowpass filter and downsample
it.
But how can I find the converting ratio? Is it 11025/24000 or
24000/11025?
And I am new to DSP and also Matlab. So, anyhelp to write this sys in
Matlab?Please help if you can.
thanks a lot in advance!!!
Reply by Ron N.●January 24, 20082008-01-24
On Jan 24, 12:29 pm, "hsquared" <hnin...@yahoo.com> wrote:
> Hi,
>
> I have a quantized input audio signal file (.wav).
> I want to convert the sampling rate from 11025 Hz to 24000.
> I know that I have to upsample the signal, lowpass filter and downsample
> it.
You don't have to. You could just interpolate any
samples needed using various splines, or a Sinc or
windowed-Sinc kernel.
IMHO. YMMV.
--
rhn A.T nicholson d.0.t C-o-M
Reply by bharat pathak●January 24, 20082008-01-24
First do an upconversion by 2. With this the new sample
rate will be 22050 Hz. now the problem is the handover
of data from 22050 Hz to 24000 Hz. This can be solved
by means of polynomial interpolation of 3rd order. meaning
take 4 adjacent samples and apply polynomial interpolation.
one of the best polynomials for your application are
"catmull-rom" also known as "4 point, 3rd order Hermite".
Search on the web and you will get the equations.
reference: http://ccrma.stanford.edu/~jos/resample/
Regards
Bharat Pathak
www.arithos.com
~dsp Simplified
>On Jan 24, 12:29 pm, "hsquared" <hnin...@yahoo.com> wrote:
>> Hi,
>>
>> I have a quantized input audio signal file (.wav).
>> I want to convert the sampling rate from 11025 Hz to 24000.
>> I know that I have to upsample the signal, lowpass filter and
downsample
>> it.
>
>You don't have to. You could just interpolate any
>samples needed using various splines, or a Sinc or
>windowed-Sinc kernel.
>
>
>IMHO. YMMV.
>--
>rhn A.T nicholson d.0.t C-o-M
>
Reply by Andor●January 25, 20082008-01-25
Ron wrote:
> hsquared wrote:
>
> > Hi,
>
> > I have a quantized input audio signal file (.wav).
> > I want to convert the sampling rate from 11025 Hz to 24000.
> > I know that I have to upsample the signal, lowpass filter and downsample
> > it.
>
> You don't have to. �You could just interpolate any
> samples needed using various splines, or a Sinc or
> windowed-Sinc kernel.
Ron
Signal resampling using kernel-interpolation (e.g. sinc, polynomials,
dirichlets, gaussian, etc.) is a special case of the upsampling,
filtering and downsampling procedure. Don't you agree?
@h^2: http://ccrma.stanford.edu/~jos/resample/
Regards,
Andor
Reply by Rick Lyons●January 25, 20082008-01-25
On Thu, 24 Jan 2008 14:29:05 -0600, "hsquared" <hnin720@yahoo.com>
wrote:
>Hi,
>
>I have a quantized input audio signal file (.wav).
>I want to convert the sampling rate from 11025 Hz to 24000.
>I know that I have to upsample the signal, lowpass filter and downsample
>it.
>But how can I find the converting ratio? Is it 11025/24000 or
>24000/11025?
>And I am new to DSP and also Matlab. So, anyhelp to write this sys in
>Matlab?Please help if you can.
>
>thanks a lot in advance!!!
Hello hsquared,
to make life a little easier for yourself,
you can upsample by 320, lowpass filter, and
then downsample by 147. I thought I could throw
a little MATLAB code together to help you.
However, that initial interpolation by 320
requires an FIR filter that has over a thousand
taps. Dealing with such filters makes me nervous.
For being new to DSP, and new to MATLAB, you
sure picked an "exciting" problem to work on.
I suggest you upsample/filter in multiple stages
so as to keep your filters of a reasonable length.
Perhaps upsample/filter by 10 and then 32 (10*32=320).
Or possibly upsample/filter by 8, by 8 again, and
by 5 (8*8*5=320).
Sorry hsquared but I don't have the time to
figure out exactly what's best to do right now.
Below is some code, but it's not working terribly
well.
Good Luck,
[-Rick-]
---------------
% Code for hsquared from Rick Lyons
clear, clc
Fs_in = 11025;
Fs_out = 24000;
Nsamples = 500; % Number of time samples
Time = (0:Nsamples-1)/Fs_in;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create an Input (time-domain) sequence
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ToneFreq = 2*1102.5; % Freq of test tone
Input = cos(2*pi*ToneFreq*Time); % Input sequence
% plot Input sequence
figure(1)
subplot(2,1,1)
plot(Time, Input, '-bo','markersize', 4)
axis([0, max(Time), 1.2*min(Input), 1.2*max(Input)])
title('Input Seq.')
grid on, zoom on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Upsample by 320
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
U = 320; % Upsample factor
Upsampled = zeros(size(1:U*length(Input))); % Upsampled sequence
Upsampled([1:U:length(Upsampled)]) = Input;
Upsampled = Upsampled(1:length(Upsampled) -U +1); % Truncate trailing
zeros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design linear-phase lowpass FIR filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NumTaps = 1295; % Number of FIR filter taps
B = fir1(NumTaps, (2/U)*Fs_in/Fs_out); % Filter coeffs
% plot filter freq response
figure(2)
freqz(B, 1, 512, U*Fs_in) % plotting command
zoom on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Filter the upsampled sequence
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Filter_out = filter(B, 1, Upsampled);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Downsample by 147
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
D = 147; % Decimation factor
Output = Filter_out(1:D:length(Filter_out)); % Final output
% plot Output sequence
Time_new = (0:length(Output)-1)/Fs_out; % New time vector for
plotting
figure(1)
subplot(2,1,2)
plot(Time_new, Output, '-ro','markersize', 4)
axis([0, max(Time_new), 1.2*min(Output), 1.2*max(Output)])
title('Output Seq.')
grid on, zoom on
Reply by Ron N.●January 25, 20082008-01-25
On Jan 25, 4:53 am, Andor <andor.bari...@gmail.com> wrote:
> Ron wrote:
> > hsquared wrote:
>
> > > Hi,
>
> > > I have a quantized input audio signal file (.wav).
> > > I want to convert the sampling rate from 11025 Hz to 24000.
> > > I know that I have to upsample the signal, lowpass filter and downsample
> > > it.
>
> > You don't have to. You could just interpolate any
> > samples needed using various splines, or a Sinc or
> > windowed-Sinc kernel.
>
> Ron
>
> Signal resampling using kernel-interpolation (e.g. sinc, polynomials,
> dirichlets, gaussian, etc.) is a special case of the upsampling,
> filtering and downsampling procedure.
Hi Andor,
I tend to think the reverse: e.g. up/down sampling with
filtering seems like a special case implementation of
kernel interpolation.
Is there a reason we are parsing "special case of"
differently? Perhaps it's because I studied numerical
methods before I learned any practical DSP theory?
IMHO. YMMV.
--
rhn A.T nicholson d.0.t C-o-M
Reply by Andor●January 25, 20082008-01-25
On 25 Jan., 19:15, "Ron N." <rhnlo...@yahoo.com> wrote:
> On Jan 25, 4:53 am, Andor <andor.bari...@gmail.com> wrote:
>
>
>
>
>
> > Ron wrote:
> > > hsquared wrote:
>
> > > > Hi,
>
> > > > I have a quantized input audio signal file (.wav).
> > > > I want to convert the sampling rate from 11025 Hz to 24000.
> > > > I know that I have to upsample the signal, lowpass filter and downsample
> > > > it.
>
> > > You don't have to. �You could just interpolate any
> > > samples needed using various splines, or a Sinc or
> > > windowed-Sinc kernel.
>
> > Ron
>
> > Signal resampling using kernel-interpolation (e.g. sinc, polynomials,
> > dirichlets, gaussian, etc.) is a special case of the upsampling,
> > filtering and downsampling procedure.
>
> Hi Andor,
>
> I tend to think the reverse: e.g. up/down sampling with
> filtering seems like a special case implementation of
> kernel interpolation.
Well, every kernel interpolation can be written as an upfirdn-
procedure (exercise to the reader: given a kernel psi(t), what is the
filter in the upsample-filter-downsample procedure for rational
sampling rate changes?). It just occured to me that the opposite is
true as well (although given a filter, the equivalent interpolation
kernel is not unique).
>
> Is there a reason we are parsing "special case of"
> differently? �Perhaps it's because I studied numerical
> methods before I learned any practical DSP theory?
Regards,
Andor
Reply by Rick Lyons●January 26, 20082008-01-26
On Thu, 24 Jan 2008 14:29:05 -0600, "hsquared" <hnin720@yahoo.com>
wrote:
>Hi,
>
>I have a quantized input audio signal file (.wav).
>I want to convert the sampling rate from 11025 Hz to 24000.
>I know that I have to upsample the signal, lowpass filter and downsample
>it.
>But how can I find the converting ratio? Is it 11025/24000 or
>24000/11025?
>And I am new to DSP and also Matlab. So, anyhelp to write this sys in
>Matlab?Please help if you can.
>
>thanks a lot in advance!!!
Hello hsquared,
did you ever solve your interpolation
problem?
[-Rick-]
Reply by Michel Rouzic●January 27, 20082008-01-27
Rick Lyons wrote:
> you can upsample by 320, lowpass filter, and
> then downsample by 147.
Wow, excuse me, but why do you suggest that? That's horrible to
encourage such practices, and it makes interpolation by a non-integer
ratio much harder than it is. Here's what I would suggest instead :
First, define how precise a filtering you want by choosing how large a
windowed sinc function you would use (in numbers of bins). We'll call
this value sincsize (sorry about the poor naming scheme). Go through
each sample of your new, interpolated signal you're trying to create.
Now, for each of these new samples, calculate the position it matches
to in the original signal (for example, if you're at sample index 100
in the new signal, you'll get the value 100 * 11025 / 24000 = 45.9375,
but let's call this value indexA).
Now, go through each original sample between indexes calculated by
indexA - (sincsize/2) (rounded up to the next integer number) and
indexA + (sincsize/2) (rounded down, or if you prefer truncated).
Weight the value at these indexes (which we'll call indexX) using a
windowed sinc centered on indexA. The formula giving for that would
be, using the Blackman function as a window, in C-ish pseudo-code:
weighted_value = original_signal[indexX] * (0.42 - 0.5*cos(2*pi *
(indexX-indexA) / sincsize) + 0.08*cos(4*pi * (indexX-indexA) /
sincsize)) * sin(2*pi*0.5 * (indexX-indexA)) / (indexX-indexA)
You would sum every of these weighted values into the value in the new
signal at indexA, and do that for every integration of indexA. Thus,
you would simply and efficiently interpolate by a non-integer
resampling ratio using a variant of time-domain convolution by a
windowed sinc FIR. I only hope I didn't lose anyone during the course
of my explanation.
Reply by Michel Rouzic●January 27, 20082008-01-27
Erratum :
Michel Rouzic wrote:
> it makes interpolation by a non-integer
> ratio much *SOUND* harder than it is.
More like :
weighted_value = original_signal[indexX] * (0.42 - 0.5*cos(2*pi *
((indexX-indexA) / sincsize + 0.5)) + 0.08*cos(4*pi * ((indexX-
indexA) / sincsize + 0.5)) * sin(2*pi*0.5 * (indexX-indexA)) / (indexX-
indexA)
I always forget that the Blackman function doesn't peak at x = 0.0 but
at half its size.