Code covered by the BSD License  

Highlights from
Bit Packet Analyzer

image thumbnail

Bit Packet Analyzer




The Bit Packet Analyzer can be used to analyze bit streams for repeating patterns (e.g. preamble)

BitPacketAnalyzer (inVector, lenPack)
%% BitPacketAnalyzer by Igal Yaroslavski
%  Display bit packets side by side, with variable packet length and variable
%  number of packets to display. The reason being an easy way to analyze packet
%  patterns e.g. preambles and etc

function BitPacketAnalyzer (inVector, lenPack)
% InVector: vector of bits to analyze
% lenPack: Length of the packet, at @ lenth bit graphics switch to new line
% if inVector contatins more than N*lenPack elements the vector is zero
% padded to the next pack.
% maxNpacks: max packets to display, if there's more - show only first packets.

maxNpacks = 100;

%% Shape data
nElements = numel(inVector);

if (size(inVector,2) > 1) % if
    inVector = reshape(inVector,nElements,1);

numPackets = nElements/lenPack;
intNumPackets = ceil(numPackets);

if(numPackets > maxNpacks) % if there's more packets then nMax, truncate the input
    intNumPackets = maxNpacks;
    outVector = inVector(1:intNumPackets*lenPack);
elseif(numPackets ~= intNumPackets) %zero padding is needed
    nZeros = lenPack*intNumPackets - lenPack*numPackets;
    outVector = [inVector; zeros(nZeros,1)];
    outVector = inVector;

clear inVector numPackets;

% shape the data to show packets in lines
outVector = (reshape(outVector, lenPack, intNumPackets))';

%% Find vertices for patches
outVector = flipud(outVector);
[y,x]=find(outVector == 1);
x = x'; y = y';
xpatch = [x-1; x ; x; x-1];
ypatch = [y-1; y-1; y; y];

%% Plot patches
f = figure('visible','off');
ha = axes('visible','off','XTickMode','manual');
h = patch(xpatch,ypatch,'k');

set(h,'Parent', ha);
set(ha,'XTick', []);
set(ha,'YTick', []);
axis(ha, 'tight');

title(['Bit Packet Analysis, Packet Length = ', ...
    num2str(lenPack), '# of Packets = ', num2str(intNumPackets)]);

Contact us