Arithenco and arithdeco not working with zeros
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
%%
0 commentaires
Réponses (1)
Abhimenyu
le 4 Oct 2023
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")
disp(message)
disp("decoded message")
disp(decoded_message)
%%
This can properly encode and decode any message containing zeros.
I hope this helps!
Thank you,
Abhimenyu.
0 commentaires
Voir également
Catégories
En savoir plus sur Denoising and Compression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!