what is wrong with pskmod 'Elements of input X must be integers in the range [0, M-1]'

10 visualizaciones (últimos 30 días)
I want to encode and modulate a figure and recover it through (15,7) BCH code.
I have already set M = 2, and the array 'code' are all 0 and 1. But I was told the 'pskmod' function arguments are wrong, 'Elements of input X must be integers in the range [0, M-1].'
I don't know how to debug. Could you please help me?
% ------------- show figure ---------------
A=imread('test.jpg');
A_shrunk = imresize(A,0.2); % we’ll reduce the resolution, as otherwise the file size is too large
% imshow(A_shrunk) % displays the shrunken image
% size(A_shrunk)% we get the figure is 318*566*3
Bs = reshape(A_shrunk,[318*566*3,1,1]); % resizes this image from a pixel array of three colours to a one-dimensional data stream
C = de2bi(double(Bs)); % converts these values to binary representation
% You can then resize this array to a linear, one-dimensional array.
% this data stream C is then what you can communicate over your channel.
% recover the image from the binary sequence
% BS_rec = uint8(bi2de(C)); % convert bits to pixel values.
% A_rec = reshape(BS_rec,[318,566,3]); % reshape back to a coloured pixel array.
% imshow(A_rec) % display the recovered image.
%----------- mod and code-----------
C1 = C(:)';
M = 2;
n = 15;
k = 7;
C0 = zeros(1,2);
CC = [C1,C0];
CC = reshape(CC,617102,k);
msg = gf(CC,1);
code = bchenc(msg,n,k);
whos code
Name Size Bytes Class Attributes code 617102x15 37026152 gf
txpsk = pskmod(code,M);
Error using pskmod
Expected input number 1, X, to be one of these types:

double, single, int8, uint8, int16, uint16, int32, uint32

Instead its type was gf.

Error in pskmod (line 94)
validateattributes(x, {'double','single','int8','uint8','int16','uint16',...
% scatterplot(txpsk);
% title('Noisy PSK Scatter Plot')
%----------- demode ---------
SNR = 5;
out = awgn(txpsk,SNR);% set the SNR
demodsig = pskdemod(out,M);
decodsig = bchdec(demodsig,n,k);
decodsig(4319714) = [];
decodsig(4319713) = [];
Re = reshape(decodsig,[318*566*3,8]);
BS_rec = uint8(bi2de(Re)); % convert bits to pixel values.
A_rec = reshape(BS_rec,[318,566,3]); % reshape back to a coloured pixel array.
imshow(A_rec) % display the recovered image.
%---------calculate the BER ----------
err = length(find(decodsig~=C1));
BER = err/length(C1);
BER_theory = qfunc(sqrt(2*SNR));

Respuesta aceptada

Image Analyst
Image Analyst el 20 de Jun. de 2022
Editada: Image Analyst el 20 de Jun. de 2022
I don't know what code is but it's an object of type "gf". The pskmod wants code to be double, single, int8, uint8, int16, uint16, int32, uint32. Now it looks like code is just a regular matrix so maybe you could do
code = uint8(code);
to cast it to a type it likes, but I don't know if that will work -- I'll leave you to test that.
You also said you need to learn how to debug and you can do that here:
  1 comentario
Siheng Liu
Siheng Liu el 21 de Jun. de 2022
Hi, I have successfully run the pskmod function, but another problem occurs.
The bchdec function requires a GF input code, so I use 'demodsig = gf(demodsig);' to transmit it to gf. However, the gf function stuck.
% ------------- show figure ---------------
A=imread('test.jpg');
A_shrunk = imresize(A,0.2); % we’ll reduce the resolution, as otherwise the file size is too large
% imshow(A_shrunk) % displays the shrunken image
% size(A_shrunk)% we get the figure is 318*566*3
Bs = reshape(A_shrunk,[318*566*3,1,1]); % resizes this image from a pixel array of three colours to a one-dimensional data stream
C = de2bi(double(Bs)); % converts these values to binary representation
%----------- mod -----------
C1 = C(:)';
M = 2;
n = 15;
k = 7;
C0 = zeros(1,2);
CC = [C1,C0];
CC = reshape(CC,617102,k);
msg = gf(CC);
code = bchenc(msg, n, k);
txpsk = pskmod(double(code.x),M);
% scatterplot(txpsk);
% title('Noisy PSK Scatter Plot')
%----------- demode ---------
SNR = 5;
out = awgn(txpsk,SNR);% set the SNR
demodsig = pskdemod(out,M);
demodsig = gf(demodsig);
decodsig = bchdec(demodsig, n, k);
decodsig(4319714) = [];
decodsig(4319713) = [];
Re = reshape(decodsig,[318*566*3,8]);
BS_rec = uint8(bi2de(Re)); % convert bits to pixel values.
A_rec = reshape(BS_rec,[318,566,3]); % reshape back to a coloured pixel array.
imshow(A_rec) % display the recovered image.
%---------calculate the BER ----------
err = length(find(decodsig~=C1));
BER = err/length(C1);
BER_theory = qfunc(sqrt(2*SNR));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by