Error in AWGN in MATLAB
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Manns
el 25 de Abr. de 2024
Respondida: Infinite_king
el 26 de Abr. de 2024
How do I correct the following error in MATLAB? MATLAB code attached.
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
Error in awgn (line 157)
y = sig + noise;
Error in Rev2 (line 20)
received_low = awgn(lenna_bits, SNR_low, 'measured');
clc;
clear all;
% Load the lenna image
lenna = imread('lenna.png');
% Convert image to grayscale
lenna_gray = rgb2gray(lenna);
% Convert pixel values to bits
lenna_bits = reshape(de2bi(lenna_gray(:), 8, 'left-msb').', [], 1);
% BPSK modulation
Eb_No_low = 0;
Eb_No_high = 4;
SNR_low = 10^(Eb_No_low/10);
SNR_high = 10^(Eb_No_high/10);
% Transmit and receive at low SNR
received_low = awgn(lenna_bits, SNR_low, 'measured');
% Demodulation
decoded_low = received_low < 0;
% Reshape decoded bits to original image size
decoded_image_low = reshape(decoded_low, size(lenna_gray));
% 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)');
% Transmit and receive at high SNR
received_high = awgn(lenna_bits, SNR_high, 'measured');
% Demodulation
decoded_high = received_high < 0;
% Reshape decoded bits to original image size
decoded_image_high = reshape(decoded_high, size(lenna_gray));
% 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)');
0 comentarios
Respuesta aceptada
Infinite_king
el 26 de Abr. de 2024
Hi James Manns,
The function 'awgn'expects 'double' type as input. It seems 'lenna_bits' is of type 'uint8'. So, type casting the 'lenna_bits' to 'double' will resolve the problem.
received_low = awgn(double(lenna_bits), SNR_low, 'measured');
Refer the documentation of 'awgn' function :- https://www.mathworks.com/help/comm/ref/awgn.html#d126e7136:~:text=ans%20%3D%20logical%0A%20%20%201-,Input%20Arguments,-collapse%20all
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Color en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!