Phase locked loop FM detection in Max

Here is an example of audio from the patch.

The source is a speech by Barack Obama which is FM modulated on an audio carrier at 23040 Hz.  Warning turn down the volume. You can hear as the PLL locks on to the signal. Then some of the params are tweaked in such a way that it is impossible to lock on to the signal, but the algorithm keeps on trying – producing an interesting result

A picture of the signal as its locking-on and when it loses the lock:

[original post]

A phase-locked loop algorithm running in Max (gen~)

The patch is unstable – but actually demodulates FM now.

download

in max-projects: https://github.com/tkzic/max-projects

folder: demodulation/max/phase-locked-loop

patch

gen-fm-detector2.maxpat

(also uses output from modem3.maxpat in folder: demodulation/max/)

instructions

  • run modem3.maxpat
  • set FM modulation level to less than 250
  • run gen-fm-detector2.maxpat
  • turn up audio output and try presets

notes

Two things: 1) I really don’t know what I’m doing with gen~ and 2) There are serious issues with the P and I coefficients in the algorithm. There is no ‘D’ coefficient yet – nor do I know whether its needed.

The thing that finally got it working was the loop filter component – which cleans up the output of the phase detector. The phase detector is essentially a phase ring modulator which contains not only the error signal, but also the sum of the incoming carrier and the reference oscillator. So the low pass filter gets rid of the high frequency component. By setting the resonance and cutoff extremely low, you can make the PLL start going a bit crazy in a beautiful way, lots of motion and spectral shifting.

Need to go through and analyze the output of the various stages, now to get the coefficients set properly – also, may need some kind of AGC on the input stage. Its very sensitive to over modulation and will distort badly.

Its interesting to play with the coefficients and hear the difference in how the demodulation works. By slowing down the P coefficient  it not only slows lock response, but during lock, the output is muffled  – so the P coefficient acts as a low pass filter – because it changes how responsive the circuit is in detecting changes in the input signal frequency (i.e., modulation).

There’s a weird thing going on – a fixed carrier is getting mixed with the error signal (output)   The patch is using notch filters to eliminate it, but it seems like it shouldn’t be there at all. Or should get filtered by the Loop filter.

Another thing to mention if I haven’t already is that I’m using a somewhat inefficient way to detect phase difference. Its the convert to complex and slope detection method used in the differentiator – but done using signals from reference oscillator instead of from delayed samples from original signal. Simply multiplying the two signals without complex conversion would probably do.

DSP based Software Defined Radio for FM Demodulation

DSP tools for FM demodulation.

By Ali Naveed, et al.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/34520/Design%20Report.pdf

Abstract:

Software Defined Radio is an emerging technology that has been an active re-search topic for over a decade. The terms software defined radio and software radio are used to describe radios whose implementation is largely software-based. These radios are reconfigurable through software updates. There are also wider definitions of the concept. A software defined uses digital signal processing (DSP) for coding, decoding, modulating, and demodulating data.

The proper implementation of SDR is far away from our approach and the experience which we have gained during the three years studies in the B.E program of Industrial Electronics. That is why, this project is the design, construction, and testing of an FM receiver. The design is split into two portions, the analog FM front end and the digital demodulator. The job of the front end is to receive and down convert the RF signal to a frequency that is low enough to be processed by a DSP processor.

The second portion of the design is the demodulator. The phase lock loop method of demodulating FM signals is used. The phase lock loop demodulator is designed in the digital domain on a DSP processor.

Updating ruby in Mac OS

5/2014 These instructions failed on Snow leopard 10.6.8 – see following note:

Note: To install rvm, there are some dependencies – for example gcc – If you have not installed xcode developer tools, or any typical linux tools – rvm will try to install homebew and probably fail. So it may not be practical to update your version of Ruby this way…

original post

Used rvm – explained here – but I have extracted relevant instructions below:

http://stackoverflow.com/questions/3696564/how-to-update-ruby-to-1-9-x-on-mac

start here:

1. Update /etc/paths as explained here:

sudo nano /etc/paths

Add 2 following lines:

/opt/local/bin
/opt/local/sbin

 

then reboot your terminal

2. Then install rvm:

As The Tin Man suggests (above) RVM (Ruby Version Manager) is the Standard for upgrading your Ruby installation on OSX: https://rvm.io

To get started, open a Terminal Window and issue the following command:

\curl -L https://get.rvm.io | bash -s stable --ruby

( you will need to trust the RVM Dev Team that the command is not malicious – if you’re a paranoid penguin like me, you can always go read the sourcehttps://github.com/wayneeseguin/rvm )

3. When it’s complete you need to restart the terminal

4. To get the rvm command working.

rvm list known

( shows you the latest available versions of Ruby )

rvm install ruby-2.0.0-p247

For a specific version, followed by

rvm use ruby-2.0.0-p247

or if you just want the latest (current) version:

rvm install current
rvm use current

( installs the current stable release – at time of writing ruby-2.0.0-p247 – please update this wiki when new versions released )