One approach to demodulating FSK would be to adjust the tuning frequency above or below both FSK frequencies, essentially creating a BFO. The output will consists of FSK in the audio range, which can be bandpass-filtered in code to retrieve the 1s and 0s.

Attached is a set of traces that may help to explain what's going on in the receiver. (BTW, I'm the one who suggested to OBC that, despite the simplicity of the hardware, the underlying theory might not be a suitable beginner's topic. Also, beginner's projects need to have a high probability of success; otherwise, a neophyte is likely to become discouraged. This project, in particular, has sketchy prospects for a satisfying outcome, depending on where one lives. I nearly threw in the towel myself, when I was initially unable to pick up anything in my fringe reception area. It was only my confidence in the underlying theory that kept me going. But, all that notwithstanding, I've decided to try for a simpler explanation at least. Maybe the illustration will help.)

In the top set of traces, there are two sinewaves: one in red, which is the audio signal, and one in gray, which is the RF carrier. When the audio signal is used to multiply the carrier, the product we end up with is an amplitude-modulated (AM) radio signal. This is shown in magenta. This is the waveform what leaves the antenna at the radio station and makes its way into our little radio via its own antenna. By that time, the peak amplitude can be measured in microvolts — millivolts, if we're lucky.

This tiny signal is presented to pin A3 of the Propeller via a capacitor. Also connected to A3 is a 10 megohm resistor from A4. A counter is configured in feedback mode (normally used for sigma-delta ADC), which reads pin A3 and, at the next clock interval (12.5ns later) outputs the opposite signal (i.e. 0 -> 1 and 1 -> 0) to A4. This "negative feedback" will tend to keep the signal on A3 centered on Vdd/2, which is the Propeller's digital input threshold. But, becasue the feedback resistor is so large, and because there's residual capacitance between the Propeller's pins and ground, the effect of the A4 output on A3 won't be instantaneous. So if the signal coming in on A3 goes very high, it may take several clock periods for a low on A4 to bring it back down. So, the higher the signal on A3, the more 0s we'll see on A4; and the lower the signal on A3, the more 1s we'll see on A4.

If we were using this counter as an ADC, we could set its FRQx to 1 and let it count the number of 1s it sees on A3 in a given interval. This count would be proportional to the average signal strength on A3 during that interval. But we're not going to do that. Instead, all we need is that string of 0s and 1s on pin A4. This is shown as signal "ADC" in the middle of the attached image, in magenta. If you squint your eyes, you can almost make out the sinusoids (inverted) from the modulated signal, even though, at each instant, A4 is either high or low.

Two additional counters are used to form the square wave signals I and Q, shown in blue and green. These signals have the same frequency as the carrier, which is how we tune the radio. They are 90° out of phase from each other, though, and have an unknown phase relationship with the incoming carrier. Now, here's where the magic happens. We can take the ADC bitstream from A4 and /XOR (/XOR is the same as the equality function) it at every step with I & Q to produce two resultant bitstreams (shown above I and below Q on the graph). If the carrier happens to line up with I (i.e. if it's in phase with I), more high points than low of ADC will coincide with high points of I, resulting in an abundance of highs after the /XOR; and more low points than high of ADC will coincide with low points of I, again resulting in an abundance of highs after the /XOR. The opposite happens when the carrier and I are 180° out of phase. But in both cases, the number of highs and lows will be at an extreme from the norm, which is a 50% duty cycle.

On the other hand, if I is 90° out of phase with the carrier, in either direction, the highs and lows will balance out, and their number will be about equal after the /XOR. The reason for having two "local oscillator" signals, I and Q, is so we don't have to rely on just one being in the right phase with the carrier. If one is nearly in phase or 180° out of phase, the other will be closer to 90° out of phase. Moreover, we can combine the outputs of the two /XORs in such a way that the result is completely independent of the carrier's phase.

As a side note, in an analog direct-conversion receiver, the I and Q oscillators would be producing sine waves, not square waves. And these two signals would be multiplied by the incoming signal, not /XORed, to produce the instaneous Fourier sine and cosine components of the amplitude. Our use of square waves is a little shaky, since each is composed of a sine wave and its odd harmonics (see Wikipedia article) in diminishing amplitudes. For this reason, if we tuned our receiver to 550 KHz and there was a strong station at 1650 KHz (550 x 3), we might pick that up as well. A tuned antenna circuit, rather than just an inductor, would help to alleviate that possibility.

The Propeller's counters have a logic look-up table mode, that allow them to count the ones from any two-input (i.e. from two pins) Boolean function. And that includes /XOR. So we don't need any external logic to perform this function. We just tell the counters to do it for us. Then all we have to do is sample the "ones" count in a given time interval, which the counters track for us, and record the result. The green and blue traces at the bottom of the illustration show these counts, obtained over the intervals between their changes in value.

Once we have the sample counts from the /XORed I and Q, we subtract the average count (i.e. half the sampling interval) from each and square the result. Then, we add the squared values and take the square root of the sum to get the "root mean square" (RMS) amplitude of the incoming radio wave at the chosen frequency. This amplitude is a discrete sample (shown in red at the bottom of the illustration) of the original audio signal (shown in red at the top).

I hope this helps. If not, let me know where things get fuzzy, and I'll try again. (By the way, these graphs were not contrived in any way for illustration purposes but, rather, represent the output from an actual computer simulation of the radio. The data were then imported to Excel to create the graphs.)

-Phil

Addendum: Changed the notation in the text and graph from "XOR" (^) to "/XOR" (=) to reflect the results shown in the graph. The program uses XOR, but both XOR and /XOR work equally well. /XOR actually makes a better example, since it more closely follows the multiplication used in analog direct conversion receivers.

EXCELLENT explanation. Of all these RF/RFID discussions and explanations, this one has been the easiest (and most laymen) for me to follow.

One thing, please. Could you provide a snapshot of the picture that has a differenct timescale? I'm curious to see it "stretched" out so I can see the detail of the the bitstreams, and how their timing lines up with the carrier wave. I'm taking this from where you say: "We can take the ADC bitstream from A4 and XOR it at every step with I & Q to produce two resultant bitstreams (shown above I and below Q on the graph)."

Also, as a side. It seems that your resultant discrete sample lags wrt the original audio signal (the two red lines). This MUST happen, in all demodulating setups, right? You can't read the signal unless you have time to read the signal. How much is the lag? Is it only 12.5ns? I've often thought about this "lag". You can see it, sometimes, when talking to a friend on the phone, who is watching the same program on TV. His TV sounds a bit behind yours, yet you are both conversing seemlessly.

Thanks for the great explanation. This gem should be bookmarked (has been for me!).

Parsko: The lag from the TV's that you mention could be due to the speed of sound. Perhaps their TV is further away from the phone than yours is. In Phil's example, we're talking about a lag of just a few cycles at about 1 MHz so probably a couple of microseconds. I'm not sure the human ear can detect such a small lag.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

The discrete sample lags the original because of the sample interval. The longer the sample interval, the more the lag and, also, the lower the audio frequency response. In the software I posted, the sample rate is 16 KHz. So the lag could be as much as 62.5 µsec.

-Phil

Addendum: I just noticed that the function reflected in the graphs is not XOR, but NOTXOR, in otherwords, equality. It doesn't really affect the outcome, though: both work equally well. I'll have to change the notation on the original graph...

When I have time (I hope soon) I'm going to try to get one prop to talk to another wirelessly. Even if can get a few Kbaud that would be cool.

Phil: I'm thinking if I use a carrier (Say 27 MHz) FSK modulated with a bit stream, and I tune just above and just below the carrier with two pairs of I&Q frequencies, and take the RMS value of each, then I can compare those RMS values. Or I can take the difference between each RMS value and a running average of each RMS value and compare the differences. Then I would determine the input to be a 1 or 0 based on which difference is higher.

I'm just thinking that detecting a digital signal should be easier than an analog signal. I also think that FSK will be more resistant to noise than ASK.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

Comparing the RMS values should work. I don't know how much luck you'll have at 27 MHz, though. Generating clean I and Q signals with an accurate phase relationship may prove difficult. You'll probably get the cleanest signals using the counters' PLL capability, but adjusting the relative phases will be tricky.

Phil Pilgrim (PhiPi) said...
Comparing the RMS values should work. I don't know how much luck you'll have at 27 MHz, though. Generating clean I and Q signals with an accurate phase relationship may prove difficult. You'll probably get the cleanest signals using the counters' PLL capability, but adjusting the relative phases will be tricky.

-Phil

True:· Perhaps I can heterodyne it down to a lower IF and go from there.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

My problem is that when I'm fresh enough to read, I'm in a place that I can't get at my computer. So, I decided to just print this thread out so that I can carry it with me... without associated graphics, it comes to about 14 pages of printed material per thread page.... you've got yourself a good chapter in someone's book.

This thread is a classic... not a sticky... a classic. We don't have a category for classic threads, but when we do, this one belongs in it.

Thanks to Phil and everyone that spent good time doing some serious thinking about how to make the inscrutable scrutable, to make the opaque clear... and to make the salty ... well... more salty[noparse]:)[/noparse]

Hi Phil,
ok, I am a little bit late. I just experimented with your program these days. This is very impressive!
I did not want to solder on my board and to the propeller pins. Do not want to risk to kill the prop.....
So I just built up the adc on the breadboard. - There was nothing to hear than some "am radio sound."
Now I have included a transistor -see the circuit- and I am able to clearly hear and understand a radio station.
The station is roundabout 50km from my home and broadcasts with 100kW Power.

Many thanks!

One question to the specialists: There is some ugly noise with 50 or 100Hz. There are some counters left. Can't they be used for filtering?

Nicely done! Your transistor preamp is a valuable contribution to this thread, and I appreciate your taking the time to publish it here.

As to the 50/100Hz noise, it sounds like you're getting some powerline interference. It should be easy enough to program a notch filter to eliminate it. Try Googling IIR notch filter or FIR notch filter for some ideas.

I MUST post here to get this thread bumped up to the top. This is an example of an AMAZING use of the propeller.
Phil, you should REALLY consider putting a thread in the completed projects forum about this.

Also, I was wondering if a transmitter could be made for the same band.

Obviously transmission requires permission, but consider this...

In worst case scenario, if our methods of communication were to fail, I often think about how people might communicate when they have no other way. Am radio seems to be a good method, and having a cheap, easy, low power method to get the word out to the masses would be ideal. Even more ideal is to make a USB receiver that gets AM data. Or even a USB transmitter. Obviously the amount of data is limited, but its better than nothing. Consider the BBS network before the internet. Messages came from around the world through a network of BBS systems.

You really need a lot of quality analog circuitry around Phil's circuit to do a decent job of reception of something that didn't come from the tens to hundreds of thousands of Watts of power fed into a very large antenna over a good ground plane typical for a commercial AM broadcasting station.

You also need some high quality analog filtering to take the output of a Propeller counter and make a clean QRP (low power) signal out of it for transmission. You won't get much range with the amount of power (maybe 100mW) available except under very good conditions. You probably would need at least a couple of Watts of output power for any meaningful transmission range and that's with a very good antenna and fairly good conditions.

There is an Amateur Radio band (160M - 1.8MHz to 2.0MHz) adjacent to the AM broadcast band that could be used for experimentation if you have a license.

Alas, its a shame such wonderful projects become "lost" in the sheer size and high levels of activity in such Forums. At least I am happy and glad that someone (thanks Clock Loop) has "revived" this and made it noticable. I was thinking about SDRs and how a Propeller might be useful - excellent work - thanks again!

Toby said...
One of the reasons that the power levels appear to be so high is that the aerial @ 60KHz is so wavelenth short and therefore so inefficient, it has to be thumped hard to get something out.

50kw is not that much at that low frequency since the antennas are always too close to the ground for much signal to
go out toward the horizon...the signal goes straight up and must bounce multiple times to reach anyone far away...each bounce weakens the
signal. I have 1kw on 160 meters to a full size dipole at only 40' ... it's a very LONG antenna! Most of my signal goes straight up but that does
have the advantage that there is no skip zone at all. Contacts are easy from 0 miles away to about 800 miles....much farther on CW. My antenna is
strung up between 2 small crank-up towers my dad erected and the soil beneath is very dry sand.

I mentioned the WWV signal at 2.5mhz because the prop would need a pretty large antenna to pick up that signal at 60khz...it seemed that such
an elaborate antenna was impractical, but then my atomic clock picks that signal up well... no idea what the antenna inside looks like...maybe
I will pop it open and see. If I do I will post the image of the antenna in this thread. I think those clocks only listen for WWVB for a few minutes
during the night as they would have little luck on 60khz during the day.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Some mornings I wake up cranky.....but usually I just let him sleep -

For 60KHz, the usual "antenna" is a ferrite "loopstick", and they can be quite small. DigiKey sells them for their time receiver modules. I could never get one to work though, since I'm outside the prime reception zone.