# Resample with unknown rate change

I am doing digital signal processing for a software defined radio. I have a signal coming in packets of data (several samples) at an average sample rate of approximately some known value FSin. I am given a request for packets to be sent out periodically, with an average rate out of approximately FSout. If I knew these rates exactly I could resample my data by a ratio R=FSout/FSin and use a FIFO to make sure data always has somewhere to go when I get a packet and there's always data to send when I'm asked to send a packet. However, the clocks of the radio and my computer are not perfectly synchronized, so there is no exact known ratio for R. What would your solution be?

This is what I am thinking: I will have to adjust the ratio by which I resample over time to keep the size of the FIFO some target, on average. If my ratio goes too high, my buffer begins to grow and the latency gets large or it overflows, if I am using a circular buffer. If my ratio goes too high, my buffer begins to shrink and eventually underflows. I will periodically find the error between the number of elements in my buffer and the target size. The integral of this error over time, I, will be used to determine R by R=e^-I. The integrator will be set with its initial value I=-ln(R). If the buffer size drifts too high, I goes towards zero and R drops, shrinking the buffer. If it drifts too low, the opposite occurs. What do you think? Should I expect anything weird (oscillation through my feedback path, etc.)?

• sounds to me that this is Asynchronous Sample Rate Conversion (ASRC). a doable, but not small problem. you need to understand static or synchronous SRC (the polyphase $\operatorname{sinc}(\cdot)$ thing) and a little about servo-mechanism or feedback control systems to adjust that SRC rate so that, however large your buffer is, the read pointer trails the write pointer by about half of the buffer length (so that there is an equal amount of "elbow room" on both sides of the read pointer). – robert bristow-johnson Mar 20 '15 at 21:37

## 1 Answer

I have done this before and it works as long as you tune your parameters correctly. There should be a gain factor on the integrator which is < 1.0.

If your application is audio, one thing to watch for is audible pitch changes during periods when the ratio is changing. You can add a proportional term to your loop filter to tune the transient response if this is an issue.