Hello,
I wrote my own Manchester Decode block which converts
01->1 and 10->0 bits. Can someone verify if this is
the correct method to do manchester decoding? When I
compared my octave m-file version results with my
GNURadio block, the results are different. I have
also included the octave m-file equivalent.
#ifdef HAVE_CONFIG_H
#include “config.h”
#endif
#include <tdma_manchester_decode_bb.h>
#include <gr_io_signature.h>
tdma_manchester_decode_bb_sptr
tdma_make_manchester_decode_bb(void)
{
return tdma_manchester_decode_bb_sptr(new
tdma_manchester_decode_bb());
}
// forecast() estimates the number of input items (per
stream) given a request for the number of output items
(per stream).
void tdma_manchester_decode_bb::forecast(int
noutput_items, gr_vector_int &inputs_required)
{
// samples per bit X number of outputs needed
int items = noutput_items*2;
for (unsigned int i = 0; i <
inputs_required.size(); i++)
inputs_required[i] = items;
}
tdma_manchester_decode_bb::tdma_manchester_decode_bb(void)
:
gr_sync_block (“manchester_decode_bb”,
gr_make_io_signature (1, 1,
sizeof(unsigned char)),
gr_make_io_signature (1, 1,
sizeof(unsigned char)))
{
signed char d_last_bit = -1;
signed char d_get_symbol_now = -1;
signed char d_out_bit = -1;
}
// Return Values:
// 0 - Send this bit to the stream output.
// 1 - Send this bit to the stream output.
// -1 - Do not send this bit to the stream
output.
signed char tdma_manchester_decode_bb::decode(unsigned
char sample)
{
signed char output;
output = -1;
// Find start of transitions
if (sample == d_last_bit) {
d_get_symbol_now = 0;
}
// Get Symbol
if (d_get_symbol_now == 1) {
if (sample == 1)
d_out_bit = 1;
else
d_out_bit = 0;
output = d_out_bit;
}
// Update private variables
d_last_bit = sample;
if (d_get_symbol_now != -1) {
d_get_symbol_now = !d_get_symbol_now;
}
return(output);
}
// The return value is the actual number written to
the output_items, or -1 if EOF.
// Call consume_each() and pass it the number of input
values consumed or processed.
// This tells indicates how many input items were
used up.
int tdma_manchester_decode_bb::work(int noutput_items,
gr_vector_const_void_star
&input_items,
gr_vector_void_star
&output_items)
{
unsigned char *iptr = (unsigned char *)
input_items[0];
unsigned char *optr = (unsigned char *)
output_items[0];
int size = noutput_items;
int num_output_items;
signed char result;
num_output_items = 0;
for (int i = 0; i < size; i++) {
result = decode(*iptr++);
if (result != -1) {
*optr++ = result;
++num_output_items;
}
}
consume_each(noutput_items);
return num_output_items;
}
=============================================
% Octave/Matlab m-file
%
% Typical procedure to use:
% v=read_float_binary “in_file_float.txt”;
% length(v)
% a=manchester_decode_file(“out_bits_float.txt”,
v);
% save -ascii out_bits_ascii.txt v
%
function output = manchester_decode_file (filename,
invar)
last_bit = -1;
get_symbol_now = -1;
out_bit = -1;
len = length(invar);
output = 0;
f = fopen(filename, “wb”);
for i=1:len
sample = invar(i);
% Find start of transitions
if sample == last_bit
get_symbol_now = 0;
end
% Get symbol
if get_symbol_now == 1
if sample == 1
out_bit = 1;
else
out_bit = 0;
end
# output = [output out_bit];
fwrite(f, out_bit, "float");
end
% Update variables
last_bit = sample;
if get_symbol_now != -1
get_symbol_now = !get_symbol_now;
end
end
fclose(f);
George B.
[email protected]