필터 지우기
필터 지우기

Alphabet to binary translate

조회 수: 3 (최근 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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by