5 views (last 30 days)

Hello,

I have table array that is 300X1 consisting of a binary sequence [0,1,0,0,1,1,1,1,0,0,0,0,1...]

I would like to compute the probability that every second order value exists. Meaning how many 00, 01, 10, and 11 exist in the sequence. Do you have any Suggestions on how to go about it?.

Thank you

Dimitris Kalogiros
on 1 Oct 2019

clc; clearvars

% input data

N=300; % always even

x=randi([0, 1], N, 1);

% two bits words

% 00->0 , 01->1 , 10->2 , 11->3

xmsb=x(1:2:end);

xlsb=x(2:2:end);

y=2*xmsb+xlsb;

% calculation of probability

[P,edges] = histcounts(y, 'Normalization', 'probability');

yIntervalCenters=(1/2)*(edges(1:end-1)+edges(2:end));

figure; stem(yIntervalCenters, P); ylabel('probability'); grid on;

Dimitris Kalogiros
on 2 Oct 2019

You have just to apply this piece of code on chunks of the input data.

I'm giving an example:

clc; clearvars;

close all;

% input data

N=300; % always even

data=randi([0, 1], N, 1);

setLength=30;

for k=0:setLength:N-setLength

% extract an interval of data

x=data(k+1:1:k+setLength);

% two bits words

% 00->0 , 01->1 , 10->2 , 11->3

xmsb=x(1:2:end);

xlsb=x(2:2:end);

y=2*xmsb+xlsb;

% calculation of probability

edges=-0.5:1:3.5;

[P,~] = histcounts(y, edges, 'Normalization', 'probability');

yIntervalCenters=(1/2)*(edges(1:end-1)+edges(2:end));

figure(1);

stem(yIntervalCenters, P, 'LineWidth', 2); ylabel('probability');

grid on; ylim([0, 1]);

pause(1);

end

I've included some extra graphical tricks

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/483101-compute-probability-of-different-states-in-a-binary-distribution#comment_751767

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/483101-compute-probability-of-different-states-in-a-binary-distribution#comment_751767

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/483101-compute-probability-of-different-states-in-a-binary-distribution#comment_751778

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/483101-compute-probability-of-different-states-in-a-binary-distribution#comment_751778

Sign in to comment.