Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Frequency Shift Keying (FSK)


  • Please log in to reply
24 replies to this topic

#1 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 06 August 2011 - 07:03 AM

I'm currently working on a FSK circuit (http://en.wikipedia....cy-shift_keying) to interface my Windows Phone to my Netduino via audio port. Note that this is basically how the iPhone connects to the Square credit card reader, and there are Android hacking projects like this as well. The code needs to transmit bytes into a series of bits that are encoded via shifts in waveform frequency (4000Hz/8000Hz typically). On the other end, the audio signal is decoded back into a series of bits and assembled into bytes. Think old-school modem. The code should be full-duplex so performance is important, though I doubt it's too much of a concern. I'm using the Audio Jack Modem from Sparkfun (http://www.sparkfun.com/products/10331) and I have C++ code for Arduino (http://www.switch-sc...SOFTMODEM-HOWTO), but nothing in managed code. I've already written code for the Windows Phone side of things, and I could probably adapt that, but is anyone aware of a similar project already out there? The code's not super complicated obviously, but I'd rather start with something stable if available. All code will be open source along with an article at the end, so hopefully this can be a good contribution to the community.

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 06 August 2011 - 07:51 AM

IMHO, you have three choices:
  • if you own a Netduino standard or mini (not Plus), you may try to port the C++ code, then build you own Netduino custom firmware (I mean with the new FSK driver);
  • look for a modem chip that already do this task, so the interface will be very simple;
  • build your own modem circuit, with opamps and related analog circuits.
Note that the 2nd and the 3rd option would require some additional info about the FSK signal (i.e. exact frequencies, baud-rate, etc). It probably requires some specialized instrumentation, and a decent knowledge about signal processing.
I may say that the 3' would be the easier, because I'm much more addicted to the hardware than the C++ coding, but...

Finally, I'd add a 4th last-minute option. Thinking about it better, the easier way would use both an Arduino (as modem), and a Netduino talking together.
However, it depends on what you are going to do.
Cheers
Biggest fault of Netduino? It runs by electricity.

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 August 2011 - 08:28 AM

Hi Mario, I think that the softmodem reads/writes serial data to the Netduino...so Arian is looking for tips on porting the Arduino C++ code to use the SerialPort object on Netduino. Arian -- if the code on the desktop reads/writes a virtual serial port or a byte stream, you may be able to reuse large amounts of it on the Netduino... I love this interface. I look forward to seeing the finished build! Chris

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 06 August 2011 - 11:43 AM

Chris, I took a look at the links. The hardware is no more than a passive filter, so there's no demodulation. There's no modulator as well. About the sources, the SoftModem C++ code shows clearly the ADC sampling the input signal. That -probably- demodulates the audio signal. I didn't analyze deeply the code, but I suspect that the modulator is realized by using the PWM output. As far I know there's no way to do that with Netduino (at least the demodulator). At this point I also would to know whether an ADC sampling would be realizable by writing a custom native driver. Cheers EDIT: following the link present at the Sparkfun's page, it leads to a "discontinued" project. Maybe there'll be a reason...
Biggest fault of Netduino? It runs by electricity.

#5 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 07 August 2011 - 06:40 AM

Chris, I took a look at the links. The hardware is no more than a passive filter, so there's no demodulation. There's no modulator as well.


So, I'm not 100% sure how the board helps. Can you help me understand the filtering that it does?

About the sources, the SoftModem C++ code shows clearly the ADC sampling the input signal. That -probably- demodulates the audio signal. I didn't analyze deeply the code, but I suspect that the modulator is realized by using the PWM output.


As for the SoftModem C++ code, I realize that I need to do the modulating and demodulating myself. I have C# code to do that on the Windows Phone side. My main need right now is to get it working on the Netduino side. I've ported what I can of the C++ code, but there are many unknown variables/objects that I can't resolve: TCNT2, TCCR2A, ACSR. I can find references to them online, but I don't know what to do with them. Here are three sample lines:
TCCR2A = 0;
TCCR2B = TIMER_CLOCK_SELECT;
ACSR   = _BV(ACIE) | _BV(ACIS1);

There's also the odd interrupt handlers that I'm not sure how to port:
ISR(TIMER2_COMPA_vect)
{
	OCR2A += (uint8_t)TCNT_BIT_PERIOD;
	SoftModem *act = SoftModem::activeObject;
	act->recv();
#if SOFT_MODEM_DEBUG
	*portLEDReg ^= portLEDMask;
#endif  
}

I'd be glad to post my progress with the rest of it. On the other hand, I'm still not sure if this is the best approach to take.

EDIT: following the link present at the Sparkfun's page, it leads to a "discontinued" project. Maybe there'll be a reason...

I know that this is done in other projects. It's definitely possible! It's pretty basic signal analysis (count the high to low shifts over a period of time. There are only two possible frequencies, and only ever one at a time. Add some basic tolerance for signal noise, and hopefully we're good. Netduino should have power for this I'd think.

#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 August 2011 - 08:07 AM

Let's talk about the demodulation, that is the process to convert the analog signal to a digital stream of bits. There are two ways to do that: hardware or software. The hardware way would be a particular circuit that "recognizes" two (or more) frequencies, and outputs an info upon the detected frequency. It's much like a Dictionary<frequency, int>, where a certain frequency maps a bit pattern. In your case there are only two well-defined frequencies, so the output will be a boolean info. You can realize it in several ways, but it's hard to design/understand if you don't have enough practice, and some knowledge about circuits. If you are interested about this context, I may explain some detail. The software way is the digital signal processing (DSP), but does NOT imply the use of a DSP chip. Your controller should sample the ADC at a certain rate (stable enough), and make calculations on the sampled stream. The most intuitive process you may do is the FFT, then find the spectral peaks. For a simple FSK there are more efficient ways to do it, for example with a couple of digital filters (FIR or IIR). They are basically a function over a stream of samples. The SoftModem approach is really trivial, and it is not much reliable. If I understand correctly, the code measures the time between the zero-crossing points of the wave. Repeat, I am not sure about it, but at first glance it looks so... This approach is an useless effort by trying to port to Netduino. First, you must port the code paying attention to the registers, timings, etc. Secondly, that effort looks useless because it's not so reliable. If you own a Netduino standard or mini (NOT Plus), you may write a custom native driver. That driver should collect the ADC samples and make calculations over them, acting as a digital filter. From a software developer point, this would be the easier and reliable way to solve the problem. Cheers
Biggest fault of Netduino? It runs by electricity.

#7 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 11 August 2011 - 04:10 AM

Thanks for the well-thought out response Mario! It looks like the C++ code is pretty challenging, and the more I think about it, the more I think that just having output from the Netduino might not be too bad. For some reason, the project pages about this device all indicate that you should connect it to the digital pins. Since the board isn't an actual modem, but just filters, it makes more sense that it should go to analog pins. On the Netduino side, I just need to break the bytes into bits and output values at the appropriate frequencies. Since the other end is an audio input jack on a phone, it's just analog data carrying the signal. Does this make sense? Is there some other reason that those projects specified digital pins?

#8 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 11 August 2011 - 04:32 AM

Another question... the places I'm checking all seem to imply that the analog input pins are measuring relative to A. Ref from 0-1023 based on 0v to aref. Does this mean that I can't tell if I have a negative voltage, or is negative actually zero? Since my input is an audio waveform, I need to be able to distinguish polarity!

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 August 2011 - 06:28 AM

Arian, you are right about the negative voltage on the input. You should never apply a voltage below zero and above Aref, so that's a problem. Have you any basic math/signal/electric knowledge? I would suggest you the hardware way to realize the modem. You should design and realize two active bandpass filters using opamps. They are a relatively simple circuit, that allow to pass only the frequencies within a range. For instance, imagine a bandpass filter that allows to pass only frequencies whose are greater than 1000Hz and 2000Hz. If you remember any old-style Hifi-set, they have the bass-, mid- and treble-controls. The "mid" knob was a bandpass filter regulation, for frequencies 300-3000Hz (I think). When the mid knob was totally turned off, any human voice (falling in that band) was almost disappearing. Drums and whistle were very clear instead. So, back to the demodulation... The aim to to take advantage of two bandpass filters, centered on the modulation frequencies, say F0 and F1, being perfectly sinusoidal. When the signal is composed of F0, the first filters allows that wave to pass through, while the second filters "stops" it (almost) at all. Vice versa for F1. When the filters are working properly, you need another small circuit, but it is simpler. If you are scared about this kind of task, I would suggest to use an Arduino board with the Softmodem program. The serial output of the Arduino will feed the Netduino serial. Basically the Arduino should act as a modem for the Netduino. I don't think would be easy to port the Softmodem source to a Netduino, even considering native C/C++ driver. Cheers
Biggest fault of Netduino? It runs by electricity.

#10 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 16 August 2011 - 04:41 PM

I'm wondering if the purpose of the filter board is so it only passes a high digital signal when the frequency is over a certain threshold. I'm not sure how that works the other way though. If I set the pin high, what would it output (expectation would be a sine or square wave of that frequency)? I had assumed that 4khz and 8khz were the low and high bits, with no signal meaning no data. This is based on the existing code that I found. My biggest problem at the moment is that my incoming signal on the phone side is so noisy that even with the Netduino board turned off, I'm not even close to zero for my audio samples.

#11 http://androino.blogspot.c

http://androino.blogspot.c

    New Member

  • Members
  • Pip
  • 4 posts

Posted 20 September 2011 - 09:54 AM

Have you tried this using Arduino?? I'm really interesting in this kind of projects, maybe we could help eachother.

#12 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 20 September 2011 - 12:29 PM

Using Arduino (or another MCU pretty fast) should be an interesting project. Basically, the firmware must sample an ADC port at a certain rate (e.g. 8-10KHz). The collected sample feed a FIFO of a certain length, then must be performed a FFT of the queued stream. The result of the FFT is an array of complex numbers, which represents modulo and phase of the discretized frequencies. A successive search-algorithm to find out the max-modulo, will give the dominant frequency. Probably there's need for a minimal external hardware: a simple low-pass filter to avoid aliasing for the sampling. Nothing particularly complicated. Supposing a sample rate of 10KHz, it means a calculation of FFT every 100us. An Arduino runs at about 15 mips, so it should be enough...although a good FFT algorithm should be chosen. The faster is the calculation, the higher could be the symbol rate, due the precision of the FFT result. Anyone is wishing to start?
Biggest fault of Netduino? It runs by electricity.

#13 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 20 September 2011 - 04:43 PM

Anyone is wishing to start?


I'd love to, but this goes far above my tinkering level of electronics! My skills are in software so I'm over my head here!

#14 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 20 September 2011 - 04:45 PM

Have you tried this using Arduino?? I'm really interesting in this kind of projects, maybe we could help eachother.


I know that people are already doing this on Arduino. I wanted to go Netduino since I already have one! I actually found a guy doing it on Windows Phone so I've stepped back and I'll buy one from him! It's just more hardware than I bargained for. Since Intuit and Square are doing audio jack inputs for credit card info, I hoped that this couldn't be a difficult problem to solve. I guess I was really wrong!

#15 http://androino.blogspot.c

http://androino.blogspot.c

    New Member

  • Members
  • Pip
  • 4 posts

Posted 21 September 2011 - 07:00 AM

I know that people are already doing this on Arduino.


Do you know where could I find some info about that??

Thanks

#16 Arian

Arian

    Member

  • Members
  • PipPip
  • 18 posts

Posted 21 September 2011 - 07:04 AM

Do you know where could I find some info about that??

Sure, here's a blog entry where a guy named Pierre says he will be ordering some PCB's to sell his units: http://www.gupigame.com/wpbots/?p=140. I don't know if he'll provide the schematics. His site doesn't include enough info to do it yourself.

#17 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 September 2011 - 07:16 AM

Pardon the intrusion, but...being in the digital age, where everything is digital, what's the utility of a FSK modem? I mean: even a 10-years old phone communicates via digital streaming, not analog. Why should be better using such a modem instead of the straightforward digital way? (Of course other than the hobbistic/fun reason) Thank you.
Biggest fault of Netduino? It runs by electricity.

#18 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 21 September 2011 - 09:24 AM

Pardon the intrusion, but...being in the digital age, where everything is digital, what's the utility of a FSK modem?
I mean: even a 10-years old phone communicates via digital streaming, not analog. Why should be better using such a modem instead of the straightforward digital way?
(Of course other than the hobbistic/fun reason)

My quess is that there's no other way to interface with the phone directly.
Information exchange could be done over the net, but it is not always convenient.

#19 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 September 2011 - 09:32 AM

My quess is that there's no other way to interface with the phone directly.
Information exchange could be done over the net, but it is not always convenient.

I don't know iPhone and many other cells, but my old Nokia (6310i) has the ability to use it as a GPRS modem. Is it not available anymore this feature?
When you connect your/any cell to a PC, is it not possible to use it as a modem?
Biggest fault of Netduino? It runs by electricity.

#20 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 21 September 2011 - 10:52 AM

Your old Nokia could be used as a modem and it also supported serial communication (if I remember correctly). Your iPhone and newer phones can also be used to connect to the internet (see tethering) but only by using a "special" client program running on the computer (e.g. iTunes, which is hard to run on the Netduino).

The phones also connects via USB. As long as the Netduino can't be a USB host it cannot be done (I believe), and even if it can sometime in the future, you still need some way to communicate with the phone.

Some things were simplier before...


But perhaps Bluetooth could be used instead?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.