Compute probability of different states in a binary distribution

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

2 comentarios

Does 0 0 0 0 count as two 00 sequences and 1 1 1 1 0 counts as two 11 sequences or one 11 and one 10? In other words what are the rules for counting the sequences? Do you always start counting from the first element?
I start counting from the first element and try to find the duads in a serial way. Meaning that in the sequence 01110000100110
there is 01 11 00 00 10 01 10
so there is 2 diplets of 01, one of 11, 2 of 00 and 2 of 10.

Iniciar sesión para comentar.

 Respuesta aceptada

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;

5 comentarios

would you please ellaborate on the meaning of each step?
Dimitris Kalogiros
Dimitris Kalogiros el 1 de Oct. de 2019
Editada: Dimitris Kalogiros el 1 de Oct. de 2019
At the first part of the program, input data are generated. A vector x with dimension Nx1
At the second part of the program, we map pairs of bits to integers. For example, suppose that
x=[ 0 0 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 1] . Then the following vector being produced y=[ 0 1 2 3 2 1 0 2 3] .
At the third part of the program, function histogram() is being used in order to calculate probability of the produced integers set (e.g. 0, 1, 2, 3)
Thank you very much it works
Could you help me to calculate the propability within a subset (let say within the first 30 values of the sequence?) and then the other 30 values and so on and so forth?
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by