Transmitting an Image over AWGN channel

3 views (last 30 days)
Pavan
Pavan on 24 Sep 2024
Commented: Umar on 25 Sep 2024
I want to encode an image using a PSK constellation and transmit it over an AWGN channel. I have written code to transmit the symbol but my decoding logic is not working. Can someone tell me what is the best way to decode the symbol and plot an MSE v/s SNR curve ?
Here is what I have got so far,
image = imread('image_.png');
grayscaleImage = rgb2gray(image);
binaryImage = imbinarize(grayscaleImage);
bits = dec2bin(binaryImage, 1);
bits = bits(:);
constellation = exp(1i * (0:7) * pi / 3);
numSymbols = size(bits,1)/ 3;
symbols = zeros(numSymbols,1);
for i = 1:numSymbols
bitGroup = bits((i-1)*3 + 1:i*3);
index = bin2dec(transpose(bitGroup));
symbols(i) = constellation(index+1);
end
snr_db = 20;
snr_linear = 10^(snr_db / 10);
noise_variance = 1 / (2 * snr_linear);
noise = sqrt(noise_variance) * (randn(size(symbols)) + 1i * randn(size(symbols)));
received_symbols = symbols + noise;

Answers (1)

Umar
Umar on 24 Sep 2024

Hi @Pavan Anand,

You mentioned, “I want to encode an image using a PSK constellation and transmit it over an AWGN channel. I have written code to transmit the symbol but my decoding logic is not working. Can someone tell me what is the best way to decode the symbol and plot an MSE v/s SNR curve ?”

Please see my response to your comments below.

After doing analysis of your code, it sounds like you have successfully encoded an image into symbols using a PSK constellation and added noise to simulate transmission over an AWGN channel. The next steps involve decoding the received symbols back into bits and then calculating the Mean Squared Error (MSE) as a function of Signal-to-Noise Ratio (SNR). So, let me focus first on decoding logic part, after transmission, you receive received_symbols, which includes noise. To decode the received symbols back to bits: First, map each received symbol to the nearest constellation point. Then, convert the index of that constellation point back into bits. Here is how you can implement this in MATLAB:

% Assuming received_symbols is already defined
% Decode received symbols
decoded_bits = zeros(numSymbols * 3, 1);
for i = 1:numSymbols
  % Find the closest constellation point
  [~, index] = min(abs(received_symbols(i) - constellation));
  % Convert index back to binary
  bitGroup = dec2bin(index - 1, 3); % Convert index to binary (3 bits)
  decoded_bits((i-1)*3 + 1:i*3) = bitGroup(:);
end

For more information on dec2bin function, please refer to

dec2bin

% Convert binary back to image
decoded_image = reshape(str2num(char(decoded_bits + '0')), size(binaryImage));

For more information on reshape function, please refer to

reshape

Once you have your decoded image, you can compute the MSE compared to the original binary image:

% Calculate MSE
mse = mean((binaryImage(:) - decoded_image(:)).^2);

To plot the MSE against different SNR values, you will need to loop through a range of SNR values, repeat the transmission and decoding process, and store the MSE results for each SNR:

snr_db_values = 0:5:30; % Define SNR values in dB
mse_values = zeros(size(snr_db_values));
for k = 1:length(snr_db_values)
  snr_db = snr_db_values(k);
  snr_linear = 10^(snr_db / 10);
  noise_variance = 1 / (2 * snr_linear);
  noise = sqrt(noise_variance) * (randn(size(symbols)) + 1i *     randn(size(symbols)));
    received_symbols = symbols + noise;
    % Decode symbols as shown above...
    % Calculate MSE for this SNR value...
    mse_values(k) = mean((binaryImage(:) - decoded_image(:)).^2);
  end
% Plotting
figure;
semilogy(snr_db_values, mse_values, '-o');
xlabel('SNR (dB)');
ylabel('Mean Squared Error (MSE)');
title('MSE vs. SNR Curve');
grid on;

For more information on semilogy function, please refer to

semilogy

If you find that the MSE is high at certain SNR levels, consider implementing error correction techniques like convolutional coding or Reed-Solomon coding based on documentations provided in the links below.

Convolutional Encoding

Reed Solomon Code

Make sure that your simulation runs multiple trials for each SNR level to average out the effects of noise and besides MSE, consider also calculating Bit Error Rate (BER) as it provides another valuable metric for performance evaluation. Hopefully, this approach should help you decode your transmitted symbols and analyze their performance over an AWGN channel.

Let me know if you need further assistance!

  2 Comments
Pavan
Pavan on 24 Sep 2024
Edited: Pavan on 24 Sep 2024
Thank You for your answer, It is helpful.
Umar
Umar on 25 Sep 2024
Hi @ Pavan Anand,
If this answer was helpful, please don’t forget to click accept answer if it meets your requirements or you still require further assistance.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!