- https://www.mathworks.com/help/releases/R2023a/comm/ref/gf.html
- https://www.mathworks.com/help/releases/R2023a/comm/ref/bchdec.html
what is wrong with the 'gf' function in 'bchenc' and 'bchdec'?
4 次查看(过去 30 天)
显示 更早的评论
I want to encode and modulate a figure and recover it through (15,7) BCH code.
The bchdec function requires a GF input code, so I use 'demodsig = gf(demodsig);' to transmit it to gf matrix.
However, the gf function stuck. This programme can't run, nor stop.
% ------------- 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);
% ------------------------Here is the problem------------------
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));
0 个评论
回答(1 个)
Shivam
2023-10-27
Hi Siheng,
I understand that on executing the following line of the given code looks like a pause to you.
decodsig = bchdec(demodsig, n, k);
You can check the size of "demodsig" array to be 617102*15. When you call the "bchdec" function with this large array, MATLAB indicates it is "Busy" in the lower-left corner of MATLAB because the implementation of the "bchdec" function iterates 617102 times. Roughly, it takes 10 minutes for 1 lac iterations and possibly will take more than an hour to finish execution. Because of this, it might give you the impression of a pause in the code.
Also, the "Busy" status signifies that MATLAB is currently processing, not paused. The code execution will proceed once "bchdec" completes its execution.
You can refer to the following documentation to know more about the "Galois Field Array(gf)" and "bchdec" function:
I hope this helps.
Thanks.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Error Detection and Correction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!