Saturday, April 21, 2012


BALSAMO (Bloqueador Automático de Llamadas Sistemáticas, Automatizadas y Molestas y Ocultas) is a dsPIC based gadget I made to filter incoming calls. At first, I was planning to use a simple 8 bit microcontroller with one of those chips that implement Caller ID (CID) decoding and return the resulting number using a serial line, but to my surprise, all the chips I found (HT9032, CMX602B, HT95168, MT8843, PCD3316) were discontinued, so I decided to implement the CID protocols myself.

CID protocols are described in the standard ETSI EN 300 659 parts 1, 2 and 3. Part 1 details the presentation, data link and physical layers for on-hook data transmission. Part 3 details the used data encoding. Part 2 is for off-hook data transmission. As I have only implemented on-hook data decoding, I have not used part 2.

CID data is transmitted between the first and the second ring patterns, using a FSK modulation, so basically the system has to:

  1. Wait until the first RING is detected.
  2. Enable the FSK demodulator.
  3. Wait for the Channel Seizure Signal (300 bits alternating "0"s and "1"s).
  4. Wait for the Mark Signal (a block of 180 ± 25 mark bits, or 80 ± 25 mark bits).
  5. Decode the messages, and match the checksum.

The designed system has a signal conditioning stage, a hardware RING detector, a dsPIC to control everything and process the input signal, and a user interface with a 2x16 LCD, some LEDs and some pushbuttons. Also included are a relay to pick up/hang the phone, a serial port mainly for debugging purposes and a microSD card reader I have not used yet. You can find the schematics here.

The FSK encoded signal has a bitrate of 1200 bps. A typical FSK demodulator for this kind of signals has only a delay block, a multiplier (that multiplies the signal by its delayed version) and a low pass filter. Before implementing the demodulator in the dsPIC, I tested it using GNU Octave (a free software clone of Matlab). I created a FSK modulator, injected noise to the modulated signal, and implemented the demodulator. The following graph illustrates how the demodulator works with these parameters:

  • Input sequence: 0   0   1   0   1   0   1   0   1   1   0   0   1   0   1   0   1   0   1   1
  • Sampling rate: 7200 Hz (1200 * 6)
  • F0 = 2100 Hz
  • F1 = 1300 Hz
  • Carrier amplitude: -40 dB
  • Noise: -43 dB

The demodulator works perfect and the output sequence matches the input sequence even with high noise levels. The Octave script not only tests the demodulator, it also calculates the coefficients needed for the low pass filter, in Q0.15 format.

Once the demodulator was tested in Octave, firmware for the device was coded. The system is in Sleep mode until a RING is detected by the hardware RING detector. Then the dsPIC wakes up, and starts the ADC and demodulator stages. Once the calling number is decoded, it's displayed in the LCD. if it's a hidden number, or it's blacklisted, the relay is activated to pick up the phone, and then it is deactivated to hang the phone. The FSK demodulator has been coded in highly optimized dsPIC assembly. The remaining code has been written in plain C.

Right now, the system only picks up and hangs the phone, but I'd like to add a feature to play some audio tracks recorded in the micro SD card. Also I'd like to add logging capabilities, and a flexible configuration interface. If you want a software release, you can ask for it, but I'd like to implement these capabilities first.


  1. Hi
    can you send me the Octave script? I would like to use it for an other project to decode a Radio-Sonde.
    thank you in advanced
    best regards from Switzerland

    1. I'll try digging through the sources from the project when I get home. I know nothing about Radio-Sonde, but most likely you will have to adjust at least the number of delays of the dephasor filter, and maybe also the low pass filter.

  2. OK, I have located the files. How should I send you them? Be warned that code is commented in Spanish (sorry about that).

  3. Good day! do you have a code for the implementation of FSK modulator and demodulator?