# Digital Image Corrupted by AWGN

27 Ansichten (letzte 30 Tage)
James Manns am 15 Apr. 2024
Beantwortet: Walter Roberson am 17 Apr. 2024 um 23:47
Request help in solving error for the code below:
Assignment is to write MATLAB code for (1) Simulate transmission of the lenna image (attached) using BPSK. For this purpose, the pixel values have to be converted to bits, then modulated and transmitted and finally detected. Do this experiment at a low SNR Eb/No of 0 dB and also at a high SNR of 4 dB. Print the images. Compare and comment.
(2) Employ a linear error detection code (only detection and no correction) and transmit using BPSK again. The code can be your choice, and you can pick any code from the book but should not be too trivial, say a (2,1) code or a repetition code. Consider first 0 dB SNR. In this case, assume that when a packet is received in error, the detector makes a retransmission request. Count the number of re-transmission requests at 0 dB, 2 dB, 4 dB, 6 dB, 8 dB and 10 dB SNR respectively until there is no error. Plot the number of re-transmission requests against the SNR values.
(3) Use an error correction code (of your choice) using syndrome look up table and correct errors directly at the receiver without sending any retransmission request. The code cannot be a too simple code, for example, (3,1) or (4,2) etc. Show images at 0 dB and 4 dB SNR after employing error correction. Give comments comparing results with no error correction and results with error correction.
% Task 1: BPSK Transmission of lenna.pgm
% Convert image to binary
lenna_bin = reshape(dec2bin(lenna(:), 8).' - '0', 1, [])';
% BPSK modulation
lenna_modulated = 2*lenna_bin - 1;
% Eb/No values
EbNo_low = 0; % Low SNR
EbNo_high = 4; % High SNR
% Transmission at low SNR
SNR_low = 10^(EbNo_low/10);
% Transmission at high SNR
SNR_high = 10^(EbNo_high/10);
% Convert received signal back to image
% Display original and received images
figure;
subplot(2,2,1), imshow(lenna), title('Original Image');
% Task 2: Linear error detection code with re-transmission
% Define linear error detection code
% Let's use a simple parity check code
parity_check_matrix = [1 1 1 1 1]; % Parity check matrix
num_bits = length(parity_check_matrix);
% Initialize variables
SNR_values = 0:2:10;
num_retransmissions = zeros(size(SNR_values));
% Loop over SNR values
for i = 1:length(SNR_values)
SNR = 10^(SNR_values(i)/10);
% Decode received bits using parity check
decoded_bits = mod(sum(reshape(lenna_received, num_bits, [])) + 1, 2);
% Count number of re-transmissions
num_retransmissions(i) = sum(~all(decoded_bits == 0));
end
% Plot number of re-transmissions vs SNR
figure;
plot(SNR_values, num_retransmissions, '-o');
xlabel('Eb/No (dB)');
ylabel('Number of Re-transmissions');
title('Number of Re-transmissions vs SNR');
% Task 3: Error correction code with syndrome lookup table
% For error correction, let's use Hamming(7,4) code
% Define generator matrix and parity check matrix
G = [1 1 0 1; 1 0 1 1; 1 0 0 0; 0 1 1 1; 0 1 0 0; 0 0 1 0; 0 0 0 1];
H = [eye(3), transpose(G(:,5:end))];
% Generate syndrome lookup table
syndrome_table = zeros(1, 8);
for i = 1:size(H,1)
syndrome = mod(H(i,:) * G', 2);
syndrome_decimal = bi2de(syndrome, 'left-msb');
syndrome_table(syndrome_decimal + 1) = i;
end
% Initialize variables
num_errors_corrected = zeros(size(SNR_values));
% Loop over SNR values
for i = 1:length(SNR_values)
SNR = 10^(SNR_values(i)/10);
% Decode received bits using syndrome lookup table
syndrome = mod(received_matrix(:,j)' * H', 2);
syndrome_decimal = bi2de(syndrome, 'left-msb');
if syndrome_decimal ~= 0 % Error detected
error_position = syndrome_table(syndrome_decimal);
end
decoded_bits(:,j) = received_matrix([3 5 6 7], j);
end
% Count number of errors corrected
num_errors_corrected(i) = sum(sum(decoded_bits ~= lenna_bin(1:4,:)));
end
% Convert corrected bits back to image
lenna_corrected_img = reshape((sign(decoded_bits - 0.5) + 1)/2, size(lenna));
% Display corrected images
figure;
subplot(1,2,2), imshow(lenna_corrected_img), title('Corrected Image');
disp("Task 1: BPSK transmission introduces noise, resulting in degraded image quality at lower SNR.");
disp("Task 2: Using a linear error detection code helps reduce the number of re-transmissions at higher SNR levels.");
disp("Task 3: Error correction code significantly improves the image quality compared to no error correction, especially at lower SNR levels.");
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
James Manns am 16 Apr. 2024
There is a different that error that wasn't showing up before:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the
appropriate size for that dimension.
Error in Computerassignment5 (line 18)
Walter Roberson am 17 Apr. 2024 um 23:43
That line of code does not occur in what was posted. Furthermore, modulated_bits and noise_low are both not defined in the code that was posted.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Walter Roberson am 17 Apr. 2024 um 23:47
lenna_bin = reshape(dec2bin(lenna(:), 8).' - '0', 1, [])';
lenna_bin reflects the size of lenna in bits
lenna_modulated = 2*lenna_bin - 1;
lenna_modulated is the same size as lenna_bin
lenna_received_low is the same size as lenna_modulated which is the same size as lenna_bin
(sign(lenna_received_low) + 1)/2 is the same size as lenna_received_low which is the same size lenna_modulated which is the same size as lenna_bin
lenna_bin is the size of lenna in bits
You are trying to reshape something the size of lenna in bits to be the same size as lenna in pixels
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Image Transforms finden Sie in Help Center und File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by