2
$\begingroup$

I need to write my own resampling algorithm to resample sample and impulse response wav files between 44.1, 48 and 96 kHz. I'm on an embedded platform, so I don't have access to the usual libraries. The current plan is to write a resampler from scratch.

Is there anything between linear interpolation and polyphase filters as far as quality is concerned? I'm mainly interested in a simple solution, quality may suffer (for now).

I do have access to a Bluestein FFT algorithm on that platform, so FFT resampling would be an option, maybe.

Summary:

  1. which resampling algorithm should I look at?
  2. what are some common quality metrics?
$\endgroup$
8
  • $\begingroup$ Linear interpolation is polyphase fltering -- it's just polyphase filtering with a 2-point parent anti-aliasing filter. $\endgroup$
    – TimWescott
    Feb 10 at 18:32
  • 2
    $\begingroup$ You seem to be thinking of quality metrics in terms of what is the absolute best one, or set, to use. I strongly suggest that you, instead, ask yourself what matters to your application. If you're feeding acoustic data to a machine learning algorithm you probably want different resampling than if you're resampling Led Zepplin songs, and you may want yet another set of metrics if you're resampling baroque-era string ensemble music. $\endgroup$
    – TimWescott
    Feb 10 at 18:37
  • $\begingroup$ Do you have MATLAB? If you're writing your own resampler, I might be able to help you with MATLAB code to compute polyphase coefficients. It's about designing really good brickwall FIR low-pass filters. $\endgroup$ Feb 10 at 22:09
  • $\begingroup$ And if you're processing .wav files, what language are you writing this code with? It could also be done with MATLAB. If you're doing this in Python, you need to find someone else with Python code or maybe translate my MATLAB code. $\endgroup$ Feb 10 at 22:12
  • 1
    $\begingroup$ @TobiasHienzsch "quality is the most important metric" but quality means different things to different applications. You will have to be more specific. $\endgroup$
    – sina bala
    Feb 11 at 1:26

3 Answers 3

5
$\begingroup$

which resampling algorithm should I look at?

Polyphase FIR is the way to go. It's actually pretty east to implement from scratch. Much easier than anything FFT related. And you get a lot of knobs to twist to dial in the quality level that you need (number of phases, phase interpolation for asynchronous conversion, FIR length, etc)

what are some common quality metrics?

Lots

  • Passband amplitude distortion
  • Passband phase distortion
  • Passband width
  • Stop band attenuation
  • Transition band width
  • Harmonic distortion,
  • Intermodulation distortion
  • Non-harmonic noise floor
  • THD
  • memory footprint, CPU consumption, etc.

A good test signal is a combination of a few sine waves at different frequencies. You can calculate the "ideal" answer and subtract it out from your actual result.

I'm on an embedded platform, so I don't have access to the usual libraries.

I recommend developing the algorithm in Matlab, Python etc. and doing all the qualification and metrics there. Once fully verified and approved you only port the final version on the embedded platform and regression test it against the reference.

$\endgroup$
1
  • 1
    $\begingroup$ Awesome, thanks for the terminology. I have some reading to do. $\endgroup$ Feb 10 at 23:57
2
$\begingroup$

Upsample from 44.1 to 48 kHz. Then down sample that from 48 to 44.1 kHz. Make sure your result is lined up with the original and subtract the original from the up and down sampled result. The residual is error.

$\endgroup$
1
$\begingroup$

I would avoid using interpolation for up/downsampling unless absolutely necessary, ie if you have non-uniformly spaced query points. Interpolation is fine for amplitude estimation, but is poor at estimating phase since the phase is the angle around the unit circle. You need significant oversampling to get good phase estimates.

As already mentioned, polyphase FIRs are a good option, and are by no means subpar. They are used in plenty of applications.

$\endgroup$
4
  • $\begingroup$ Yeah I mean mathematically, a polyphase resampler is no different than up sampling - combined anti-image+anti-aliasing filter - down sampling. Like, not only on par, but literally giving the bitwise same result. $\endgroup$
    – sina bala
    Feb 11 at 1:29
  • $\begingroup$ @sinabala I'm not sure what exactly you mean by your comment. Are you agreeing or disagreeing? $\endgroup$
    – Baddioes
    Feb 12 at 23:51
  • $\begingroup$ Fully agreeing, even reinforcing: what you propose is not only on par, it is identical, in terms of results! $\endgroup$
    – sina bala
    Feb 13 at 0:44
  • $\begingroup$ @sinabala gotcha, thanks! $\endgroup$
    – Baddioes
    Feb 13 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.