# MATLAB: How to assign 2-bit codes to analog values

bitstringscodes

Hello,
So suppose I have an array for time and a corresponding signal.
time = [0:.2:2*pi]; signal = sin(t);
I want to be able to assign 2-bit codes (00, 01, 10, 11) for the signal values so it fulfills the following conditions:
when signal < 0 the code is '11',
when signal == 0 the code is '00',
when 0 < signal <= 0.75 , the code is '01',
and when signal > 0.75, the code is '10'.
I attached the sin wave above.
So from each data point in the sine wave, I get
00 01 01 01 01 10 10 10 10 10 10 10 01 01 01 01 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
And then the output matrix should be concatenated into one binary string like so:
bitstring = [0001010101101010101010100101010111111111111111111111111111111111]
Additionally, how can I modify the bitstring and pad it with the necessary number of zeroes on the right side to convert it into a 64-bit binary value?

t = [0:.2:2*pi]; signal = sin(t(:))signal = 32×1         0
0.1987
0.3894
0.5646
0.7174
0.8415
0.9320
0.9854
0.9996
0.9738
●bin = discretize(signal,[-inf, 0, 0.75, inf])bin = 32×1     2
2
2
2
2
3
3
3
3
3
●bin(signal == 0) = 4;codes = [1 1; 0 1; 1 0; 0 0];coded = codes(bin,:)coded = 32×2     0     0
0     1
0     1
0     1
0     1
1     0
1     0
1     0
1     0
1     0
●