-1

Problem: when I enter this code in matlab, i face the following respond :

Requested 65536x65536 (32.0GB) array exceeds
maximum array size preference (5.0GB). This
might cause MATLAB to become unresponsive.

Can anybody please run the code for me and send me the results ?

I need to show the right graphical results of the code

I = imread('lena.jpg'); % Read the image file
I = rgb2gray(I); % Convert the image to grayscale
I = imresize(I, [256 256]); % Resize the image to 256x256 pixels
p = double(I(:)); % Convert the image to a vector of pixel values
% Modulation scheme
b = p > 128; % Convert the pixel values to bits using a threshold value
s = 2*b - 1; % Convert the bits to BPSK symbols
% Carrier frequency
fc = 10000; % Set the carrier frequency to 10 kHz
fs = 100000; % Set the sampling frequency to 100 kHz
t = (65535:length(s)-1)/fs; % Define the time vector
x = s .* cos(2pifc*t); % Multiply the modulated signal by a cosine wave
% Transmit filter
[b1, a1] = butter(4, 12000/(fs/2)); % Design a bandpass Butterworth filter of order 4 and cutoff frequency 12 kHz
xf = filter(b1, a1, x); % Apply the filter to the transmitted signal
% Channel model
sigma = 0.1; % Set the noise variance
n = sigma * randn(size(xf)); % Generate AWGN with zero mean and sigma variance
Omega = 1; % Set the channel scale parameter
h = sqrt(Omega/2) * (randn(size(xf)) + 1i*randn(size(xf))); % Generate Rayleigh fading with Omega scale parameter
y = h .* xf + n; % Multiply the filtered signal by the channel and add the noise
% Receive filter
[b2, a2] = butter(4, 12000/(fs/2)); % Design a bandpass Butterworth filter of order 4 and cutoff frequency 12 kHz
yf = filter(b2, a2, y);
% Demodulation scheme
yr = yf .* cos(2pifc*t); % Multiply the received signal by a cosine wave
[b3, a3] = butter(4, 1000/(fs/2), 'low'); % Design a lowpass Butterworth filter of order 4 and cutoff frequency 1 kHz
yrf = filter(b3, a3, yr); % Apply the filter to the demodulated signal
bhat = yrf > 0; % Convert the demodulated signal to bits using a threshold value
% Output image
phat = 255 * bhat; % Convert the bits to pixel values
phat = reshape(phat, [256 256]); % Reshape the vector to a matrix
Ihat = uint8(phat); % Convert the matrix to a grayscale image
% Graphical results
figure(1) % Create a figure window
subplot(2,2,1) % Create a subplot
imshow(I) % Display the input image
title('Input image') % Add a title
subplot(2,2,2) % Create another subplot
plot(t, abs(x)) % Plot the magnitude of the transmitted signal
xlabel('Time (s)') % Add an x-axis label
ylabel('Amplitude (V)') % Add a y-axis label
title('Transmitted signal') % Add a title
subplot(2,2,3) % Create another subplot
plot(t, abs(y)) % Plot the magnitude of the received signal
xlabel('Time (s)') % Add an x-axis label
ylabel('Amplitude (V)') % Add a y-axis label
title('Received signal') % Add a title
subplot(2,2,4) % Create another subplot
imshow(Ihat) % Display the output image
title('Output image') % Add a title

1 Answer 1

0

The demodulation scheme doesn't work.

Here is the result so far, corrected.

Check the line

h = sqrt(Omega/2) * (randn(size(xf)) + randn(size(xf)));

Which has no sense at all with imaginary terms passed through the filtering stages.

enter image description here

I = imread('soe.jpg'); % Read the image file
I = rgb2gray(I); % Convert the image to grayscale
I = imresize(I, [256 256]); % Resize the image to 256x256 pixels
p = double(I(:)); % Convert the image to a vector of pixel values
% Modulation scheme
b = p > 128; % Convert the pixel values to bits using a threshold value
s = 2*b - 1; % Convert the bits to BPSK symbols
% Carrier frequency
fc = 10000; % Set the carrier frequency to 10 kHz
fs = 100000; % Set the sampling frequency to 100 kHz
t = (1:length(s))'/fs; % Define the time vector
x = s.*cos(2*pi*fc*t); % Multiply the modulated signal by a cosine wave
% Transmit filter
[b1, a1] = butter(4, 12000/(fs/2)); % Design a bandpass Butterworth filter of order 4 and cutoff frequency 12 kHz
xf = filter(b1, a1, x); % Apply the filter to the transmitted signal
% Channel model
sigma = 0.1; % Set the noise variance
n = sigma * randn(size(xf)); % Generate AWGN with zero mean and sigma variance
Omega = 1; % Set the channel scale parameter
h = sqrt(Omega/2) * (randn(size(xf)) + randn(size(xf))); % Generate Rayleigh fading with Omega scale parameter
y = h .* xf + n; % Multiply the filtered signal by the channel and add the noise
% Receive filter
[b2, a2] = butter(4, 12000/(fs/2)); % Design a bandpass Butterworth filter of order 4 and cutoff frequency 12 kHz
yf = filter(b2, a2, y);
% Demodulation scheme
yr = yf.*cos(2*pi*fc*t); % Multiply the received signal by a cosine wave
[b3, a3] = butter(4, 1000/(fs/2), 'low'); % Design a lowpass Butterworth filter of order 4 and cutoff frequency 1 kHz
yrf = filter(b3, a3, yr); % Apply the filter to the demodulated signal
bhat = yrf > 0; % Convert the demodulated signal to bits using a threshold value
% Output image
phat = 255 * bhat; % Convert the bits to pixel values
phat = reshape(phat, [256 256]); % Reshape the vector to a matrix
Ihat = uint8(phat); % Convert the matrix to a grayscale image
% Graphical results
figure(1) % Create a figure window
subplot(2,2,1) % Create a subplot
imshow(I) % Display the input image
title('Input image') % Add a title
subplot(2,2,2) % Create another subplot
plot(t, abs(x)) % Plot the magnitude of the transmitted signal
xlabel('Time (s)') % Add an x-axis label
ylabel('Amplitude (V)') % Add a y-axis label
title('Transmitted signal') % Add a title
subplot(2,2,3) % Create another subplot
plot(t, abs(y)) % Plot the magnitude of the received signal
xlabel('Time (s)') % Add an x-axis label
ylabel('Amplitude (V)') % Add a y-axis label
title('Received signal') % Add a title
subplot(2,2,4) % Create another subplot
imshow(Ihat) % Display the output image
title('Output image') % Add a title
answered Dec 9, 2023 at 21:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.