## Decoding AM-modulated serial communication

### Decoding AM-modulated serial communication

Hi,

I'm trying to determine whether there is a way with PicoScope 6, math channels and serial decoding to decode a signal (output by French EDF meters, specification only available in French at http://www.linuxembarque.free.fr/electr ... leinfo.pdf) that looks as follows:

This is a 1200 baud bit stream, AM-modulated so that a 0 bit is represented by the presence of the 50kHz carrier, and a 1 bit by the absence of the carrier.

I've first tried to use freq(A) (green curve) in the hope that it would get me something close to what I need to feed to the serial decoder, but that doesn't seem to fit the bill (first of all, I don't understand why freq(A) "gradually slopes down to 0" instead of "dropping to 0 at the end of the 'carrier block'").

Any clue?

I'm trying to determine whether there is a way with PicoScope 6, math channels and serial decoding to decode a signal (output by French EDF meters, specification only available in French at http://www.linuxembarque.free.fr/electr ... leinfo.pdf) that looks as follows:

This is a 1200 baud bit stream, AM-modulated so that a 0 bit is represented by the presence of the 50kHz carrier, and a 1 bit by the absence of the carrier.

I've first tried to use freq(A) (green curve) in the hope that it would get me something close to what I need to feed to the serial decoder, but that doesn't seem to fit the bill (first of all, I don't understand why freq(A) "gradually slopes down to 0" instead of "dropping to 0 at the end of the 'carrier block'").

Any clue?

### Re: Decoding AM-modulated serial communication

Hi sba923,

The problem is how the calculation for frequency is done and when it is done. The calculation involves counting between sets of double crossing points, so where you get a disjointed set of frequencies or sudden absences the result doesn't instantly reflect the change.

You are better of using an alternative function such as the one I created in the example psdata file and screen shot below, i.e. a low-pass filtered RMS equivalent value (you would need to adjust the scaling to get the mark/space signal optimally in view).

Regards,

Gerry

The problem is how the calculation for frequency is done and when it is done. The calculation involves counting between sets of double crossing points, so where you get a disjointed set of frequencies or sudden absences the result doesn't instantly reflect the change.

You are better of using an alternative function such as the one I created in the example psdata file and screen shot below, i.e. a low-pass filtered RMS equivalent value (you would need to adjust the scaling to get the mark/space signal optimally in view).

Regards,

Gerry

Gerry

Technical Specialist

Technical Specialist

### Re: Decoding AM-modulated serial communication

Hi Gerry,

Thx for getting back to me on this.

Your approach seems indeed the correct one, but... how does one create such a custom function?

Also, I'm experiencing something strange with your .psdata file: on one of PC it loads correctly and yields a display matching your screenshot, on another PC the orange "math channel" doesn't load...

TIA for your help.

Stéphane.

Thx for getting back to me on this.

Your approach seems indeed the correct one, but... how does one create such a custom function?

Also, I'm experiencing something strange with your .psdata file: on one of PC it loads correctly and yields a display matching your screenshot, on another PC the orange "math channel" doesn't load...

TIA for your help.

Stéphane.

### Re: Decoding AM-modulated serial communication

Hi sba923,

The custom function was created from observation. I have previously created the instantaneous RMS function, and I knew that it would, to some extent, smooth out the pulse burst, and saw that it creates a group of peaks. I then figured that a low pass filter would completely (or almost) smooth the peaks out for me, to give the mark/space equivalent.

This Math channel was a quick implementation, which is often not the best. In this case, I forgot to add you will need to adjust the cutoff frequency of the filter for it to work on significantly different signal frequencies. I'm sure there is a more elegant, effective solution which would not be dependent upon the frequency of the burst (unfortunately the obvious function, ABS{A}, gives a disjointed waveform, and still leaves signal peaks).

There could be a number of reasons why the Math channel doesn't appear on your PC. First of all check that you are using a version of PicoScope 6 that is new enough to be able to read the psdata file created by the latest version. If there is an issue importing the Math functions and the Math channel is not there, you should be able to just create the function on the PC that doesn't have it by typing it in (if you write down what it is). However, you still may not be able to see the resulting waveform due to the next problem.

One of the most common reasons that a Math channel waveform is not visible is that the scaling is defaulting to a wrong value. Unfortunately, when you create a Math channel, the scale used for the amplitude of the function is not normalized according to the expected range (i.e. based upon the function and the input/s that it is applied to). In your case, you can correct this by just comparing the Y-axes for the 2 PC's, and making the adjustment in the Math channel by checking the 'Override automatic range selection' check-box and entering the correct values.

Regards,

Gerry

The custom function was created from observation. I have previously created the instantaneous RMS function, and I knew that it would, to some extent, smooth out the pulse burst, and saw that it creates a group of peaks. I then figured that a low pass filter would completely (or almost) smooth the peaks out for me, to give the mark/space equivalent.

This Math channel was a quick implementation, which is often not the best. In this case, I forgot to add you will need to adjust the cutoff frequency of the filter for it to work on significantly different signal frequencies. I'm sure there is a more elegant, effective solution which would not be dependent upon the frequency of the burst (unfortunately the obvious function, ABS{A}, gives a disjointed waveform, and still leaves signal peaks).

There could be a number of reasons why the Math channel doesn't appear on your PC. First of all check that you are using a version of PicoScope 6 that is new enough to be able to read the psdata file created by the latest version. If there is an issue importing the Math functions and the Math channel is not there, you should be able to just create the function on the PC that doesn't have it by typing it in (if you write down what it is). However, you still may not be able to see the resulting waveform due to the next problem.

One of the most common reasons that a Math channel waveform is not visible is that the scaling is defaulting to a wrong value. Unfortunately, when you create a Math channel, the scale used for the amplitude of the function is not normalized according to the expected range (i.e. based upon the function and the input/s that it is applied to). In your case, you can correct this by just comparing the Y-axes for the 2 PC's, and making the adjustment in the Math channel by checking the 'Override automatic range selection' check-box and entering the correct values.

Regards,

Gerry

Gerry

Technical Specialist

Technical Specialist

### Re: Decoding AM-modulated serial communication

Hi Gerry,

You don't actually answer my question about creating custom functions for Math Channels. LowPass() is built-in, but RMS() isn't. How do you program the latter? Using some extensibility mechanism described in the SDK?

As far as the incorrect behavior on one of my PCs: all PCs have the exact same version of PicoScope 6 installed, so that cannot be the culprit.

I don't have the offending PC here (I'm on a business trip), but what I remember is that your channel doesn't show up at all under Tools / Math Channels / Loaded, so this is not a display / range issue IMVHO.

Let's address point #1 first, so that I can myself create any custom function to use in a Math Channel, starting by recreating your RMS() function.

TIA again

Best regards,

Stéphane.

You don't actually answer my question about creating custom functions for Math Channels. LowPass() is built-in, but RMS() isn't. How do you program the latter? Using some extensibility mechanism described in the SDK?

As far as the incorrect behavior on one of my PCs: all PCs have the exact same version of PicoScope 6 installed, so that cannot be the culprit.

I don't have the offending PC here (I'm on a business trip), but what I remember is that your channel doesn't show up at all under Tools / Math Channels / Loaded, so this is not a display / range issue IMVHO.

Let's address point #1 first, so that I can myself create any custom function to use in a Math Channel, starting by recreating your RMS() function.

TIA again

Best regards,

Stéphane.

### Re: Decoding AM-modulated serial communication

Hi sba923,

As you didn't mention anything about the SDK and as you said that you have tried the built in function freq(A) I assumed that you were using PicoScope 6 and knew the process of how to create a Math channel (as all you have to do to create one is press the create button, and follow the prompts of the Math Channel Wizard). So, I also assumed that you were asking how I created the function conceptually.

So, to answer your last question, in PicoScope 6 you just apply the function: LowPass(sqrt(average(A^2)), 10000). However, in the SDK you would need a Math library for sqrt() and average() (or you would need to create them yourself), and you would need a signal processing library for LowPass(), (or you could create a moving average filter).

As mentioned, I'm sure there is a more elegant solution to this, so I will have a think about it when I get a moment.

Regards,

Gerry

As you didn't mention anything about the SDK and as you said that you have tried the built in function freq(A) I assumed that you were using PicoScope 6 and knew the process of how to create a Math channel (as all you have to do to create one is press the create button, and follow the prompts of the Math Channel Wizard). So, I also assumed that you were asking how I created the function conceptually.

So, to answer your last question, in PicoScope 6 you just apply the function: LowPass(sqrt(average(A^2)), 10000). However, in the SDK you would need a Math library for sqrt() and average() (or you would need to create them yourself), and you would need a signal processing library for LowPass(), (or you could create a moving average filter).

As mentioned, I'm sure there is a more elegant solution to this, so I will have a think about it when I get a moment.

Regards,

Gerry

Gerry

Technical Specialist

Technical Specialist

### Re: Decoding AM-modulated serial communication

Hi sba923,

Here is a better coded implementation:

**************************************************************************************************

* Create a mark/space waveform out of a modulation burst waveform *

* Method *

* while the value of the sample is outside the threshold limits of no activity *

* and it is less than 1 modulation period since the waveform was modulated *

* set the output waveform to mark *

* otherwise the line is idle *

* let the output waveform default to space *

*************************************************************************************************

createMarkSpace()

{

mark = FALSE; // line is idle, i.e. no modulation

sampleVal = buffers[ ]; // get next sample value

burstCount = 0; //

while ( (sampleVal > upper_threshold) && (sampleVal < lower_threshold) && (burstCount < modulationPeriod) )

{

mark = TRUE;

sampleVal = buffers[ ];

burstCount++;

}

}

Note that we don't have access to the protocol, so this is untested and incomplete, (missing declarations, array elements, and correct references to the function you would be using it in) but is written to show you the implementation without having to refer to other code.

Regards,

Gerry

Here is a better coded implementation:

**************************************************************************************************

* Create a mark/space waveform out of a modulation burst waveform *

* Method *

* while the value of the sample is outside the threshold limits of no activity *

* and it is less than 1 modulation period since the waveform was modulated *

* set the output waveform to mark *

* otherwise the line is idle *

* let the output waveform default to space *

*************************************************************************************************

createMarkSpace()

{

mark = FALSE; // line is idle, i.e. no modulation

sampleVal = buffers[ ]; // get next sample value

burstCount = 0; //

while ( (sampleVal > upper_threshold) && (sampleVal < lower_threshold) && (burstCount < modulationPeriod) )

{

mark = TRUE;

sampleVal = buffers[ ];

burstCount++;

}

}

Note that we don't have access to the protocol, so this is untested and incomplete, (missing declarations, array elements, and correct references to the function you would be using it in) but is written to show you the implementation without having to refer to other code.

Regards,

Gerry

Gerry

Technical Specialist

Technical Specialist

### Re: Decoding AM-modulated serial communication

Sorry for the confusion.

I'm not using the SDK, just learning PicoScope 6.

When I opened up your file it showed a Math Channel with a formula of LowPass(RMS(A)) where RMS() is not one of the available functions in the Math Channel wizard.

So I started to make things up: there must be some "development kit" that allows one to implement non-built-in functions that can then be used in the formula for a channel.

Looking at your latest post: you show some "code", where does that code go? All I can do in the Math Channel wizard is create a formula that combines built-in functions such as freq(), peak(), average() etc.

Sorry if my questioning sounds dumb, I'm still discovering the product....

I'm not using the SDK, just learning PicoScope 6.

When I opened up your file it showed a Math Channel with a formula of LowPass(RMS(A)) where RMS() is not one of the available functions in the Math Channel wizard.

So I started to make things up: there must be some "development kit" that allows one to implement non-built-in functions that can then be used in the formula for a channel.

Looking at your latest post: you show some "code", where does that code go? All I can do in the Math Channel wizard is create a formula that combines built-in functions such as freq(), peak(), average() etc.

Sorry if my questioning sounds dumb, I'm still discovering the product....

### Re: Decoding AM-modulated serial communication

If you highlight the Maths channel in the dialog, then select Duplicate it will move it into the Library section where you can edit it and see the actual equation.

The LowPass( RMS (A) ) is just the name Gerry gave to the maths channel, the equation is LowPass(sqrt(average(A^2)), 10000)

The LowPass( RMS (A) ) is just the name Gerry gave to the maths channel, the equation is LowPass(sqrt(average(A^2)), 10000)

Martyn

Technical Support Manager

Technical Support Manager

### Re: Decoding AM-modulated serial communication

Guess what? I've accidentally discovered that I can move the channel from "Loaded" to "Library" and that it then gets editable, revealing the formula Thanks for the confirmation.

Now what about the "piece of code" that Gerry posted? What kind of code is that and where do you use/insert it in PicoScope?

Again, sorry for my rookie questions...

Now what about the "piece of code" that Gerry posted? What kind of code is that and where do you use/insert it in PicoScope?

Again, sorry for my rookie questions...

### Re: Decoding AM-modulated serial communication

That code is not for PicoScope 6, but the sort of thing you would do if writing your own application from scratch.

Martyn

Technical Support Manager

Technical Support Manager

### Re: Decoding AM-modulated serial communication

Great! Now I see the light again

Thx for the clarification.

Now I know it's not possible to extend PicoScope 6 with custom functions maybe I should suggest this as a new feature...

Thx for the clarification.

Now I know it's not possible to extend PicoScope 6 with custom functions maybe I should suggest this as a new feature...

### Re: Decoding AM-modulated serial communication

This is already on the wish list

Martyn

Technical Support Manager

Technical Support Manager