フィルターのクリア

Arithenco and arithdeco not working with zeros

1 回表示 (過去 30 日間)
Bernard Gonzales
Bernard Gonzales 2022 年 4 月 28 日
回答済み: Abhimenyu 2023 年 10 月 4 日
Why does arithenco/arithdeco not work with an input sequence including zeros and is there a way to work around this?
Example) Input message would be [2,1,2,1,2,0,0] and the decoded sequence is [3,2,3,2,3,1,2]. Whereas if I have an input message of [2,1,2,1,2,1,2], my decoded sequence is identical to the input as [2,1,2,1,2,1,2].
Below is my testing code. I believe you'll need the Signal Processing ToolBox for the arithenco/arithdeco functions.
clc;
clear all;
close all;
message = [2,1,2,1,2,0,1];
%% Encoder
table_size = height(message);
rows = table_size(1);
encodedY = [];
for row = 1:rows
coeff_row = message(row,:);
% Calculate unique values
source = unique(coeff_row);
for i=1:length(source)
counts(i)=length(strfind(coeff_row,source(i)));
end
seq=zeros(1,length(coeff_row));
for i=1:length(coeff_row)
seq(i)=strfind(source,coeff_row(i));
end
% Get arithmetic code for the block
code = arithenco(seq, counts);
% Store the block's code
encodedY = [encodedY; {code}];
end
%% Decoder
decodedY = [];
for row = 1 : size(encodedY)
temp = cell2mat(encodedY(row,:));
dseq = arithdeco(temp,counts,length(seq));
decodedY = [decodedY;dseq];
end
%%

回答 (1 件)

Abhimenyu
Abhimenyu 2023 年 10 月 4 日
Hi Bernard,
I understand that you want to decode the messages containing zeros using “arithenco” and “arithdeco” functions of MATLAB. You can modify the code to map the “decodedY” values back to the “source” as you have used “unique” function to map the “message” to “seq. Here is the modified code:
clearvars;
close all;
message = [2,1,2,1,2,0,2];
%% Encoder
table_size = height(message);
rows = table_size(1);
encodedY = [];
for row = 1:rows
coeff_row = message(row,:);
% Calculate unique values
source = unique(coeff_row);
for i=1:length(source)
counts(i)=length(strfind(coeff_row,source(i)));
end
seq=zeros(1,length(coeff_row));
for i=1:length(coeff_row)
seq(i)=strfind(source,coeff_row(i));
end
% Get arithmetic code for the block
code = arithenco(seq, counts);
% Store the block's code
encodedY = [encodedY; {code}];
end
%% Decoder
decodedY = [];
for row = 1 : size(encodedY)
temp = cell2mat(encodedY(row,:));
dseq = arithdeco(temp,counts,length(seq));
decodedY = [decodedY;dseq];
end
%modified here
decoded_message = zeros(size(decodedY));
for i = 1:length(decodedY)
decoded_message(i) = source(decodedY(i));
end
disp("message")
message
disp(message)
2 1 2 1 2 0 2
disp("decoded message")
decoded message
disp(decoded_message)
2 1 2 1 2 0 2
%%
This can properly encode and decode any message containing zeros.
I hope this helps!
Thank you,
Abhimenyu.

カテゴリ

Help Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by