Jump to content
  • 0

Custom decoder for Manchester Encoding


Sid Price

Question

6 answers to this question

Recommended Posts

@Sid Price,

Do you really need a custom decoder?  Manchester is pretty easy to decode.  There's lots of ways to do it too.  I'd be tempted to apply a matched filter to the doublet, and then treat the signal as BPSK.  That'd be the "optimal" solution, but often you don't need the "optimal" solution so a lot of other ways exist to do it as well.  Let's see ... you can find an example filter here that might work well, and here's an example PLL you could use too.  You could even get fancy, given that you are only ever "multiplying" by one or negative one, and so remove all the multiplies from the filter as well.  You could go even fancier and adjust this symmetric filter for this purpose too ...

Indeed, there's lots of options.  What more do you need?

Dan

Link to comment
Share on other sites

@D@n Thanks for the quick response.

>>> Do you really need a custom decoder? 

Well I have a large captured stream I need to decode, so, yes I could somehow do it by hand but, since I need to possibly examine many captures, having the AD2 do it is desirable.

I looked at the links you included and I have to admit they are way beyond my feeble mind.

Many thanks, Sid

Link to comment
Share on other sites

@Sid Price,

Oops ... this is the scopes and instrumentation forum and not one of the FPGA forums, isn't it?  Ok, then your request makes more sense.  I'm sure @attila will have a comment for you then--he's been very diligent about answering and resolving AD2 requests.

Me?  I'd probably build a basic Octave script to do what I described above with a data capture.  I'd first run everything through a filter, as discussed above.  I think Octave has a "conv" (or is it "convolve"?) function that can apply the filter.  Remember--the filter isn't a rectangle, but a pair of rectangles with opposite polarity.  I'd then make a copy and calculate something like X(t-T/2)*x(t+T/2), where s(t) is the filtered sample stream and T is the number of samples per doublet.  If you filter that new stream narrowly around your sample rate, perhaps even via an FFT based filter, you should find a maximum at the mid-point of every sample.  That would save you the hassle of needing to run the PLL--something not nearly as appropriate on sampled data.  Once you know where to sample, you should then be able to just take a threshold to get each individual bit.  It's easy once you've done it once or twice, although I can understand why you might think of it as black magic if you'd never done it before.

Dan

Link to comment
Share on other sites

Hi @Sid Price

You could try the following custom interpreter.
Like ieee802.3 https://en.wikipedia.org/wiki/Manchester_code

image.png.b83f73a3839d18cf4d6972e2e19146af.png

// Decoder
// rgData: input, raw digital sample array
// rgValue: output, decoded data array
// rgFlag: output, decoded flag array

const hzCoding = 100000;
const cBits = 11;
const iDio = 0; // DIO 0
const fPolarity = 0;

const cSamples = rgData.length // number of acquisition samples
const cSamplePerBit = hzRate/hzCoding;
var pData, fData = 0;   // previous and current bit value
var cByte = 0;          // byte count

for(var i = 0; i < cSamples ; i++){
    var s = rgData[i];    // current sample
    if(fPolarity) s = ~s; 
    pData = fData;
    fData = 1&(s>>iDio); 
    
    if(pData != 0 && fData == 0){ // falling edge 
        var bValue = 0;
        for(var b = 0; b < cBits; b++){
            var ii = round(i+(0.75+b)*cSamplePerBit); // sample at 3/4 of clock
            s = rgData[ii];
            if(fPolarity) s = ~s;
            fData = 1&(s>>iDio);
            bValue <<= 1; // MSbit first
            if(fData) bValue |= 1; 
        }
        var iEnd = round(i+(cBits+0.5)*cSamplePerBit);
        for(; i < iEnd; i++){
            rgFlag[i] = cBits;
            rgValue[i] = bValue;
        }
        fData = 0;
    }
}
// Value to text
// value: value sample
// flag: flag sample

function Value2Text(flag, value){
  switch(flag){
    case 0: return "X";
    default: return value.toString(2);
  }
}
Value2Text(1,1)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...