Does anyone know or have any hints/ideas how i to write a software phase-locked loop ?

I have an audio signal digitised by a sound card and want to create a software 'oscillator' and then phase-lock it to a carrier frequency, which has been digitised by the sound card.

This might sound bizzarre to most, but anyone have any idea ??:confused:
Posted on 2001-09-16 18:23:17 by CodeBug
In a wav file, you have the number of channels (mono, stereo) the sampling rate, the number of bits per sample and the data samples. With this information, it should be possible to obtain the phase of the signal and use it to program the oscillator.
Posted on 2001-09-19 14:27:24 by Dr. Manhattan
A Phase Locked Loop or so called PLL is the core of many hardware syncro IC, basically it goes like this:

You have a source oscilator with a given variable phase you get this signal together with your own oscilator IC into a phase discriminator IC that outputs a signal that is proportional to the phase diference between the 2 input signals, then you use this output signal to drive/modify your oscilators phase until the phase difference between the 2 oscilators is allmost zero. (the frequency must be the same also)

This is the big picture....at hardware level...

to do this in software is possible but at a very low level frequency or with some help from hardware IC's it can be done at a medium frequency 2Mhz up to 50Mhz may be a little higher...

It all depends on what you want to do, audio should work with curent micros (Intel Pentium) pretty nice IF you do not do other realtime tasks....

the last trick i have seen in this PLL stuff was a small ROM memory prewritten with an offset value that shifts a register counter according to a diffrence betwwe 2 digital signals (values are between -2 up to +2 from a simple and fast substract IC)

it was fast and very simple (only 3 simple basic IC's), used inside a FDC controller based on NEC8272 FDD Controller IC .... working at 16Mhz max, pretty hard to understand how/why it worked....

but this can be called software anymore?

Anyway ask me and i will answer if you need more detailed info
Posted on 2001-09-25 15:25:26 by BogdanOntanu
It can be done....

BUT, you have a bit of learning ahead of you.

If you already know of the LaPlace Transforms (S-Space) (which you might if you know what PLL's are to begin with), this is an advantage.

LaPlace Transforms are a special case transform of a more global set of transforms, called Discrete Transforms (Z-Space). When the Sample rate of a Discrete transform is set to infinity, you end up with LaPlace Transforms (Analog, real-time sampling).

But since you want to do this on a CPU which has a FINITE sample rate, you have to use the Discrete Z-Transforms, because your CPU will only sample at say, 500Mhz.

Next, A PLL is a feedback control system, just as BogdanOntanu discribed. Just like LaPlace you will need to build the Discrete Transfer function, and then build its Chracteristic Equation. This is an algorithm that describes what multiplier you should multiply the input from, say, 3 times ago, plus a multiplier from 2 times ago, etc. etc. right up to the current input sample.

This means for discrete filter systems you need to create a history buffer, of a length desired by the PLL characterist equation.

THIS IS ALL DSP THEORY by the way...

A Characteristic equation might look like..

Out_Now = In_-3x * (0.234) + In_-2x *(-.0023) + In_-1 *(0.1) + In *(-0.432)

So in a software sence its very easy to program.. But the headache is going thru the Discrete transforms of the system to get a Characteristic equation that models the responce you want.

BTW: This is exactly how win-amp's digital equalizers work, by making characteristic equations to filter one frequency and then amplify it or not. This is also why there is a "lag" in responce when you change a setting. The filter needs to build up a new HISTORY of samples to properly continue filtering. Your stero is ANALOG, so there is an infinite sample rate, and thus any changes will be filtered instantly, in Real-Time.

Well.. there you have it, DSP 101. :grin:

Hope this helps. (PS: this is a 4th year university topic)
Posted on 2001-09-30 10:56:39 by NaN