2 bit binary signal to numerical value

4 ビュー (過去 30 日間)
Yusuf Dhoda
Yusuf Dhoda 2019 年 10 月 7 日
コメント済み: Yusuf Dhoda 2019 年 10 月 24 日
I have a 32768x2 double array that contains a 2 bit binary signal. I want to convert this 2 bit binary signal to a value between 1 and -1. For example:
01 ----- 1
00 ----- 0.5
10 ----- -0.5
11 ----- -1
I want to store the results in a 32768x1 array
Thank you

採用された回答

Deepak Kumar
Deepak Kumar 2019 年 10 月 10 日
編集済み: Deepak Kumar 2019 年 10 月 10 日
Try the below code. It should work fine.
clc
clear all
a=your_array; %Assign your array to the vaiable 'a'
L=size(a,1);%Get number of rows in a
d=bi2de(a,'left-msb'); %Convert binary vectors to decimal numbers with 1st column as MSB. use, d=bi2de(a) if you want 1st column as LSB
for i=1:L
switch d(i)
case 1
b(i)=1;
case 0
b(i)=.5;
case 2
b(i)=-.5;
case 3
b(i)=-1;
end
end
b=b'; % Final answer
  1 件のコメント
Yusuf Dhoda
Yusuf Dhoda 2019 年 10 月 24 日
Thank you very much for your help. The code worked well

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by