ep-4xx13 DSP – week 13

Signal processing with radio

  • unintended interactions
  • using the wrong tools
  • measuring the invisible
  • antennas
  • propagation is frequency dependent
  • Extreme frequencies, negative frequencies?

links

Demodulation of signals in Max

These patches are works in progress. Please contact me if you have questions about how they work.

  • Modem.maxpat – modulation/demodulation
  • gen-fm-detector2.maxpat – a phase locked loop in gen~. Use with modem.maxpat – but turn FM modulation level down to about 250.
  • pid-mrmapes2.maxpat – Using a PID controller to control oscillators
[wpdm_file id=15]

Frequencies and modes

  • Arduino transmitter: AM 1330 kHz.
  • Wireless micorophone: Wide FM 676 mHz.
  • Cordless phone: Narrow FM 926 mHz.
  • Cell phone: Digitally encrypted trunking FM 836 mHz.
  • Macbook trackpad: Noise 5 mHz.
  • Macbook AC adapter: Noise 600-1400 kHz.
  • Wifi: Digitally encoded PCM 2.4 gHz.
  • FM broadcast band: Wide FM 89.7 mHz
  • TV audio 600 mhz/660 mhz FMW

 

Notes on rtl-sdr source code – first impressions

I did a quick read of source code (rtl-fm.c) today.

Basically it opens an input stream of IQ samples from the rtl-sdr device, demodulates filters, and outputs audio.

Other than usual madness with threads and locking – the code is fairly straightforward. Not well commented – but clear enough that we could extract the input streaming and frequency (device) control to make a Max external. One question would be whether or not to do the downsampling in the external, or in Max?

Rough estimate would be this project would involve about 1-2 weeks of analysis and hacking. Possibly less – but there is a learning curve – and a heuristic stuff which is required to work with the hardware.

Fortunately it actually works in MacOS and Windows – and there are plenty of other examples to compare it to. But this is not a casual evening project.

 

Compliling rtl-sdr from source on Mac OS

notes

Just compiled rtl-sdr using  instructions below, from: http://sdr.osmocom.org/trac/wiki/rtl-sdr

!! but did not run: sudo make install – or sudo ldconfig !!

so the programs are just running locally in: tkzic/rtl-sdr/build/src

I didn’t want to overwrite the macports versions which are running in the exec path.

after compiling I was able to successfully test by running this from rtl-sdr/build/src:

./rtl_fm -f 94900000 -W -s 200000 -r 48000 - | play -r48000 -t s16 -L -c 1 -

which caused annoying pre-christmas music from WHOM to ruin this peaceful morning.

—————————————————————

Building the software

rtlsdr library & capture tool

You have to install development packages for libusb1.0 and can either use cmake or autotools to build the software.

Please note: prior pulling a new version from git and compiling it, please do a “make uninstall” first to properly remove the previous version.

Building with cmake:

cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig

In order to be able to use the dongle as a non-root user, you may install the appropriate udev rules file by calling cmake with -DINSTALL_UDEV_RULES=ON argument in the above build steps.

cmake ../ -DINSTALL_UDEV_RULES=ON

Piping raw IQ data from rtl-sdr to Max

notes

Here is a discussion about mkfifo (pipes) but  I can’t seem to get Max to interpret the FIFO as audio samples

http://www.reddit.com/r/RTLSDR/comments/rd15f/some_noob_questions_after_succesfully_getting/

I think I know how to figure out the streaming IQ thing now. Capture samples to a file, then look at the format. Then maybe pipe the file through something like auconvert to make it into a wave file. If that works, then maybe there is a way to to it as streaming.

Or figure out how to stream from tcp/ip version to audio.

PID controller in Max

Here is a PID controller (proportional, integral, derivative) in Max that controls the pitch of an oscillator so you can watch how a process responds to various setting of PID coefficients. It features an external perturbance generator (ie., noise maker) to check how fast the system can adjust and continue.

Tried using fiddle~ for frequency detection (as the sensor input) but it provides faulty data below about 200hz – and that totally messes up the PID. so I am just using the actually frequency being used to set the oscillator as the response sensor.

update:  Tristan Jehan wrote a Max external that extends lower frequency range of  [fiddle~]. It would be worth trying for this patch.

The PID algorithm is written in javascript.

download

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

folder: pid-controller

patch: pid-mrmapes2.maxpat

javascript code: pid.js

Instructions

  • turn on audio
  • change test interval to something like 20
  • click on message boxes to change set point. Listen and watch results
  • try different presets – which alter PID settings and then try changing the set point. For example, with the 2nd preset you will see overshoot and oscillation during settling phase.

more about PID controllers

wikipedia page: http://en.wikipedia.org/wiki/PID_controller

 

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.

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 )

ep-4xx13 DSP – week 12

Mashups

notes

tools

Holiday book recommendations:

Assignment

Work on final projects. Due in class December 16th

 

ep-3xx41 Max – week 12

modern user Interface design:

Max For Live – part 2

notes

patches

  • chord2.amxd – a generative midi effect
  • gizmo-mod-example.amxd – (a Max help file made into an audio effect)

[wpdm_file id=14]

links

Max patches

  • Basic Max For Live audio effect
  • M4L instrument
  • adapting a help file
  • Live packs (Max for Live essentials from Cycling74)

Assignment – generative music

Design a patch that composes music

Next monday I will be meeting with all of you individually. Its a great opportunity to ask questions about anything – or get help with projects, ideas, etc.,