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.)?