Re: very simple phase-locked loop pitch detection in C

Dave Long <[email protected]>
Newsgroups gmane.culture.people.kragen.discuss
Message-ID <[email protected]>
> This is probably a good example of Guido's observation about the
> readability of reduce on non-associative arguments: almost always, an
> explicit loop would be easier to read.

My bad.

> I think this is the kind of PLL that Massalin, around p.99 of her
> dissertation, calls a "FLL", for "frequency-locked loop".

Definitely failed to communicate then.  It tracks the difference  
between leading edges of the local oscillator and the signal, so even  
with matched frequencies, the phase difference gets integrated.  (if  
the frequencies differ enough that there are multiple leading edges  
for each lagging, then they should sum linearly so the feedback  
signal is even stronger)

If I understand properly, the dot product style of phase detector has  
a region where it produces the wrong sign for a stable lock, whereas  
this detection will lock properly for all phase differences.

-Dave

>> # odelta: calculate the adjustment by comparing lead/lag of cycle  
>> starts
>> # oprime: scan-update the local oscillator value
>> odelta  = lambda osc, sig: compare(wav(osc),wav(sig))/4096.0
>
> This looks like a bit of cheating --- for every "sample", you  
> generate a
> whole new signal as if that oscillation were continued for 1024  
> samples?
> Maybe I didn't understand.


That was an artifact of my tracing output; I was trying to simulate a  
signal that changed relatively slowly (sig is not the sample, the  
1024 elements of wav(sig) are), and because I'm not sure how to  
express an actual FM signal (product of sines?), it's doing step- 
function frequency changes.  (might be interesting to try with just  
phase, to see how well this would track phase-shift keying?)

>> zeroph  = lambda w:   [(i<0 and j>0) for i,j in zip(w[:-1],w[1:])]
>
>
>  I wonder, would this work
> better with (i<0 and j>=0)? With < and > it ought to miss the
> zero-crossing occasionally.


True, but in general it's not very robust; you'd probably want to  
loosen the logic, and look for something that went from significantly  
below zero to significantly above within a small number of samples,  
rather than tightening it.

> The page I found about LIAs makes them sound like they're just
> what I'm doing in the longer C pitch-detection program: taking a
> low-pass-filtered "dot product" between the input and a second
> 90°-offset waveform generated by the oscillator.

The cool thing about LIAs is that they introduce an artificial  
switching into a signal (the example H&H gives is a telescope that  
physically switches the mirror back and forth from the subject to a  
control).  This way, stuff that correlates well with the switched  
condition is highly likely to be signal, and instrument noise will  
likely be the same no matter which way the switch is pointing.  (and  
1/f noise should be lower at a high f than at dc)  Maybe I haven't  
understood what you're describing, but it sounds to me more like AM  
demodulation via PLL.

-- 
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.