what is wrong with pskmod 'Elements of input X must be integers in the range [0, M-1]'
10 次查看(过去 30 天)
显示 更早的评论
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
txpsk = pskmod(code,M);
% 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));
1 个评论
Karim
2022-6-20
Can you attach 'test.jpg' ? You can do this using the paperclip symbol in the respons.
采纳的回答
Image Analyst
2022-6-20
编辑:Image Analyst
2022-6-20
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:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!