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
% Convert binary back to image decoded_image = reshape(str2num(char(decoded_bits + '0')), size(binaryImage));
For more information on reshape function, please refer to
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
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.
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!