Alphabet to binary translate

2 views (last 30 days)
Gabriel
Gabriel on 14 Nov 2023
Commented: Dyuman Joshi on 14 Nov 2023
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 Comments
Gabriel
Gabriel on 14 Nov 2023
% 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 on 14 Nov 2023
" 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?

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 14 Nov 2023
Edited: KALYAN ACHARJYA on 14 Nov 2023
% 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.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!