error while using BCHencoder

7 views (last 30 days)
As_rar
As_rar on 8 Nov 2020
Edited: Pooja Kumari on 15 Jan 2024
Hello everyone
I would ask about BCHencoder ..
I use BCHencoder from communication toolbox , as in https://www.mathworks.com/help/comm/ref/comm.bchencoder-system-object.html
and this error come to me
Error using comm.BCHEncoder/setParameters
N and K must be positive, double precision integer scalars
all k and n are integers
this is my code
ds=randi([0 1],18,1); %generating a random string
enc = comm.BCHEncoder(20,18); %creating Object of BCH encoder (ECC: error corecting code)
c=step(enc,ds);
the error come from " step(enc,ds)"
i use matlab 2020b
could anyone help me how to fix the error
thank you so much
  1 Comment
Jorge Cadena
Jorge Cadena on 29 Sep 2021
I have the same issue and no idea how to resolve it. Were you able to find a solution?

Sign in to comment.

Answers (1)

Pooja Kumari
Pooja Kumari on 15 Jan 2024
Edited: Pooja Kumari on 15 Jan 2024
Hi,
As per my understanding, you are facing "Error using comm.BCHEncoder/setParameters N and K must be positive, double precision integer scalars" error because value of "N" and "K" are not of correct data type or value.
The value of codeword length which is represented by "N" must take the form (2^m – 1), where m is an integer in the range [3, 16]. The message length which is represented by the "K" parameter should follow this condition that "N > K" and both should be integers.
Value of "M" which is given as "20" does not satisfy 2^m-1 property.
Example code for BCHEncoder:
% Define BCH code parameters
n = 15; % Codeword length
k = 5; % Message length
% Create BCH encoder and decoder objects
bchEncoder = comm.BCHEncoder('CodewordLength', n, 'MessageLength', k);
bchDecoder = comm.BCHDecoder('CodewordLength', n, 'MessageLength', k);
msg = randi([0 1], k, 1); % message signal
encodedMsg = step(bchEncoder, msg); % Encoding message signal
% Introduce errors
receivedMsg = encodedMsg;
errorPositions = [3, 7]; % Example error positions
receivedMsg(errorPositions) = ~receivedMsg(errorPositions); % Flip bits to introduce errors
[decodedMsg, errorStats] = step(bchDecoder, receivedMsg); %decoded message signal
% Find error locations by comparing the original encoded message and the received message
errorLocations = find(encodedMsg ~= receivedMsg);
You can refer to the documentation for more information on "BCHEncoder" :

Community Treasure Hunt

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

Start Hunting!