Alphabet to binary translate

2 ビュー (過去 30 日間)
Gabriel
Gabriel 2023 年 11 月 14 日
コメント済み: Dyuman Joshi 2023 年 11 月 14 日
I have a project in optical communcitaion, were i want to send a laser thorugh polarised light to a photodioder, then to two DAQ:s, one will retrieve the signal and one wants to send, and that works. Now i want to transalte the one:s and zero:s do display on a screen, what the message is, the variable namne in workspace for the recorded signal is called DAQ_1, i seem to get a problem when i have the code for i = 1:lenght(DAQ_1), i get an error. What should i change in my code?
  2 件のコメント
Gabriel
Gabriel 2023 年 11 月 14 日
% Existing binMap and binaryToText function
binMap = {'0000001', 'A';
'0000010', 'B';
'0000011', 'C';
'0000100', 'D';
'0000101', 'E';
'0000110', 'F';
'0000111', 'G';
'0001000', 'H';
'0001001', 'I';
'0001010', 'J';
'0001011', 'K';
'0001100', 'L';
'0001101', 'M';
'0001110', 'N';
'0001111', 'O';
'0010000', 'P';
'0010001', 'Q';
'0010010', 'R';
'0010011', 'S';
'0010110', 'T';
'0010111', 'U';
'0011000', 'V';
'0011001', 'X';
'0011010', 'Y';
'0011011', 'Z'};
function translatedText = binaryToText(binarySequence, binMap)
index = find(strcmp(binMap(:,1), binarySequence));
if ~isempty(index)
translatedText = binMap{index, 2};
else
translatedText = ' ';
end
end
% Assume that DAQ_1 is the variable you have in the workspace with the binary sequences
% Loop over the received binary sequences and translate them to text
for i = 1:length(DAQ_1)
binarySequence = DAQ_1{i};
% Translate the binary sequence to text using the binaryToText function and binMap
translatedText = binaryToText(binarySequence, binMap);
% Display binary sequence and translation on the screen
disp(['Received binary sequence: ' binarySequence ', Translation: ' translatedText]);
% Here, you can perform additional actions with the translated data if needed
% ...
end
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 14 日
" the variable namne in workspace for the recorded signal is called DAQ_1, i seem to get a problem when i have the code for i = 1:lenght(DAQ_1), i get an error."
Please copy and paste the full error message, that means all of the red text.
"% Assume that DAQ_1 is the variable you have in the workspace with the binary sequences"
Yeah, that won't do. You will need data to run the code.
Is DAQ_1 supposed to be obtained as user input? Or is it obtained from another source?

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

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2023 年 11 月 14 日
編集済み: KALYAN ACHARJYA 2023 年 11 月 14 日
% Existing binMap and binaryToText function
binMap = {'0000001', 'A';
'0000010', 'B';
'0000011', 'C';
'0000100', 'D';
'0000101', 'E';
'0000110', 'F';
'0000111', 'G';
'0001000', 'H';
'0001001', 'I';
'0001010', 'J';
'0001011', 'K';
'0001100', 'L';
'0001101', 'M';
'0001110', 'N';
'0001111', 'O';
'0010000', 'P';
'0010001', 'Q';
'0010010', 'R';
'0010011', 'S';
'0010110', 'T';
'0010111', 'U';
'0011000', 'V';
'0011001', 'X';
'0011010', 'Y';
'0011011', 'Z'};
%%
% Assume that DAQ_1 is the variable you have in the workspace with the binary sequences
DAQ_1={'0011000','0010011','0001100'}; % Random Test Data
% Loop over the received binary sequences and translate them to text
for i = 1:length(DAQ_1)
binarySequence = DAQ_1{i};
% Translate the binary sequence to text using the binaryToText function and binMap
translatedText = binaryToText(binarySequence, binMap);
% Display binary sequence and translation on the screen
disp(['Received binary sequence: ' binarySequence ', Translation: ' translatedText]);
% Here, you can perform additional actions with the translated data if needed
% ...
end
Received binary sequence: 0011000, Translation: V Received binary sequence: 0010011, Translation: S Received binary sequence: 0001100, Translation: L
%%
function translatedText = binaryToText(binarySequence, binMap)
index = find(strcmp(binMap(:,1), binarySequence));
if ~isempty(index)
translatedText = binMap{index, 2};
else
translatedText = ' ';
end
end
DAQ_1-You can validate the code by inputting random 7 bits in string format using an array structure, which could occur in real-time testing as well.

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by