Received Output High SNR Error

2 visualizzazioni (ultimi 30 giorni)
James Manns
James Manns il 30 Apr 2024
Risposto: Sudarsanan A K il 30 Apr 2024
How to correct received output high SNR error?
clc;
clear all;
% Load the 'lenna' image
lenna = imread('lenna.png');
% Convert the image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray), [], 1);
% Define Eb/No values for low and high SNR
Eb_No_low = 0;
Eb_No_high = 4;
% Calculate SNR values for low and high SNR
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(double(lenna_bits), SNR_low, 'measured');
% Demodulate received bits at low SNR
decoded_low = received_low < 0;
% Reshape decoded bits to original image size at low SNR
szin = size(lenna_gray,1:2);
decoded_image_low = reshape(decoded_low, prod(szin), []); % reshape into binary words
decoded_image_low = uint8(bi2de(decoded_image_low)); % convert to uint8 vector
decoded_image_low = reshape(decoded_image_low, szin); % devectorize
% Plot original and received image at low SNR
figure;
subplot(1, 2, 1);
imshow(lenna_gray);
title('Original Image');
subplot(1, 2, 2);
imshow(decoded_image_low);
title('Received Image (0 dB SNR)');
% Define the parity matrix
parityMatrix = [1 1 0 1 0 0 0;
1 0 1 0 1 0 0;
0 1 1 0 0 1 0;
1 1 1 0 0 0 1];
% Concatenate the identity matrix and the transposed parity matrix to form the generator matrix
generatorMatrix = [eye(4), parityMatrix]; % Transpose parityMatrix to make its dimensions compatible
% Transmit and receive at high SNR
received_high = awgn(double(lenna_bits), SNR_high, 'measured');
% Demodulate received bits at high SNR
decoded_high = received_high < 0;
% Reshape decoded bits to original image size at high SNR
decoded_image_high = reshape(decoded_high, size(lenna_gray, 1), []);
% Plot original and received image at high SNR
figure;
subplot(1, 2, 1);
imshow(lenna_gray);
title('Original Image');
subplot(1, 2, 2);
imshow(decoded_image_high);
title('Received Image (4 dB SNR)');

Risposta accettata

Sudarsanan A K
Sudarsanan A K il 30 Apr 2024
Hi James,
The MATLAB code you have provided aims to simulate the transmission and reception of an image in a noisy environment, emphasizing the impact of signal-to-noise ratio (SNR) on image quality. However, there are a few conceptual and practical issues that might lead to unexpected outcomes. Here is a concise breakdown of these issues along with proposed modifications to enhance the simulation:
  • Lack of Modulation Scheme: Transmitting raw bits doesn't mirror real-world digital communications, where modulation is essential. For example, implement BPSK modulation using "pskmod" for transmission and "pskdemod" for reception to improve robustness and realism.
  • Improper SNR Calculation for Modulated Signals: The current SNR calculation overlooks the modulation scheme, leading to inaccurate noise modeling. Adjust the SNR calculation to reflect the modulation scheme's characteristics accurately. Also, remember that "awgn" requires the SNR input in dB.
  • Inefficient Bitstream Handling: Converting image pixels directly to a bitstream and back without considering the modulation scheme's requirements. Use "reshape" and "de2bi" for efficient bitstream conversion, ensuring it aligns with the modulation and demodulation process.
  • Incorrect Use of dec2bin and bi2dec: Potential misuse could compromise data integrity. Correctly apply "de2bi" and "bi2de" with the 'left-msb' argument for consistent bit ordering, maintaining data integrity.
Here is how you can refine your code considering the above points:
% Load the 'lenna' image
lenna = imread('lenna.png');
% Convert the image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray, 8, 'left-msb'), [], 1); % Ensure 8 bits per pixel and 'left-msb' ordering
% Define Eb/No values for low and high SNR
Eb_No_low = 0;
Eb_No_high = 4;
% Modulate using BPSK
modulated_signal = pskmod(lenna_bits, 2); % BPSK modulation
% Calculate SNR values for low and high SNR, taking into account the noise power in BPSK
% For BPSK, the bit energy is the same as the symbol energy since there is one bit per symbol
SNR_low = Eb_No_low + 10*log10(1); % Since BPSK has 1 bit per symbol, log10(1) = 0, but shown for clarity
SNR_high = Eb_No_high + 10*log10(1);
% Transmit and receive at low SNR
received_low = awgn(modulated_signal, SNR_low, 'measured');
% Demodulate received signal at low SNR
demodulated_low = pskdemod(received_low, 2); % BPSK demodulation
% Transmit and receive at high SNR
received_high = awgn(modulated_signal, SNR_high, 'measured');
% Demodulate received signal at high SNR
demodulated_high = pskdemod(received_high, 2); % BPSK demodulation
% Reshape demodulated bits to original image size
szin = size(lenna_gray,1:2);
decoded_image_low = reshape(demodulated_low, [], 8);
decoded_image_low = uint8(bi2de(decoded_image_low, 'left-msb'));
decoded_image_low = reshape(decoded_image_low, szin);
decoded_image_high = reshape(demodulated_high, [], 8);
decoded_image_high = uint8(bi2de(decoded_image_high, 'left-msb'));
decoded_image_high = reshape(decoded_image_high, szin);
% Plot original, received image at 0 dB SNR, and received image at 4 dB SNR
figure('Position', [100, 100, 1200, 400]);
% Original Image
subplot(1, 3, 1);
imshow(lenna_gray);
title('Original Image');
% Received Image at 0 dB SNR
subplot(1, 3, 2);
imshow(decoded_image_low);
title('Received Image (0 dB SNR)');
% Received Image at 4 dB SNR
subplot(1, 3, 3);
imshow(decoded_image_high);
title('Received Image (4 dB SNR)');
You can evaluate the performance using the bit error rate (BER) metric as follows:
% Calculate and display Bit Error Rate (BER)
ber_low = sum(abs(double(lenna_bits) - double(demodulated_low))) / length(lenna_bits);
ber_high = sum(abs(double(lenna_bits) - double(demodulated_high))) / length(lenna_bits);
fprintf('BER at low SNR (0 dB): %f\n', ber_low);
BER at low SNR (0 dB): 0.078496
fprintf('BER at high SNR (4 dB): %f\n', ber_high);
BER at high SNR (4 dB): 0.012567
Please refer to the following documentation pages for further details and better understanding of the use cases of respective functions:
I hope this helps!

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by