1
$\begingroup$

I’ve created an upsample and a downsample functions (x2) using polyphase FIR filter.

I have a signal which comes in chunks where sampling rate of each chunk can vary between 1x and 2x (e.g. 48000 Hz and 96000 Hz).

Is there a way to devise a test for a function that would resample the signal to 2x sampling rate (96000 Hz in my example)? I'm worried about whether anything can be wrong on the boundaries of chunks, like errors when prepending a padding before upsampling etc.

Like maybe one could make FFT of all the chunks and sum energy in each bin and compare it somehow with FFT of the whole resampled signal or something…

$\endgroup$
2
  • $\begingroup$ A "chunk" of signal (it looks like an audio signal) means simply a block of samples, correct? Does the problem definition mean that for each chunk has a constant sample rate throughout the chunk, but the sample rate can change between adjacent chunks, correct? Now if that is the case, then between two chunks that have different sample rates, how do we relate the time difference between the last sample of the previous chunk and the first sample of the current chunk? Is it 1/2 of the sampling period of the previous chunk plus 1/2 of the sampling period of the current chunk? $\endgroup$ Commented Jun 16, 2023 at 20:29
  • $\begingroup$ And, I presume, you want your output to be a faithfully resampled result with a constant and specified sample rate? Is that correct? $\endgroup$ Commented Jun 16, 2023 at 20:31

1 Answer 1

1
$\begingroup$

You can apply a standard unit testing process here. Choose a bunch of test vectors with known results (either through analytical analysis or as regression against a known-good reference implementation). The choice of vectors should be representative of your application signals AND also cover edge cases and signal properties that your algorithm or application is particularly sensitive too.

In your particular case I would start with some "close to Nyquist" sine waves and impulses. It's straight forward to calculate the error between the actual output and the ideal result.

What's less straight forward is how to define the "acceptable" error. Could be phase error, magnitude error, jitter error, causality error, time domain ringing, etc. Which one to use and what limits to set depends on you specific application.

$\endgroup$
3
  • $\begingroup$ Comparing with the result calculated by hand or another reference implementation is an obvious way to test this. I don’t see any reference resampler that can deal with variable sampling rate, hence the question about smarter solutions. Like relying on some mathematical properties. $\endgroup$ Commented Jun 16, 2023 at 13:47
  • $\begingroup$ Understood. I still think that high frequency sine waves are a really good starting point: they are sensitive to sample rate conversion in general and to any type of discontinuities and any errors are easy to quantify. A mix of a few frequencies is also useful since it can reveal any intermodulation distortion. If you get this to work correctly, chances are you are good. $\endgroup$
    – Hilmar
    Commented Jun 16, 2023 at 15:42
  • $\begingroup$ Hilmar, I'm worried about gluing together two adjacent chunks having different sample rates. Somehow we gotta define what the time difference is between the last sample of the earlier chunk and the first sample of the following chunk. That has to be nailed down. $\endgroup$ Commented Jun 16, 2023 at 20:33

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.