matlab code processing is too slow

조회 수: 1 (최근 30일)
Muhammad Abdulrazek
Muhammad Abdulrazek 2021년 11월 12일
편집: Muhammad Abdulrazek 2021년 11월 13일
Hi there,
i am working on a project but when i run my project it take a lot of time to process the script, and never finish
i use matlab2016a
why it take this time ?
Can you help me with this ?
and here is my code :
%NOMA images Logistic chaotic mapping sequence encryption
clc;
clear variables;
close all;
rand('state',32768);
randn('state',86723);
warning('off','comm:obsolete:randint')
N = 128*128*8; %Data lenghth
Pt = 0:2:40; %transmit power (dBm)
pt = (10^-3)*10.^(Pt/10); %transmit power (linear scale)
BW = 1*10^6; %BandWidth = 1MHZ
No = -174 + 10*log10(BW); %Noise power (dBm)
no = (10^-3) *10.^(No/10); %Noise power (linear scale)
d1 = 500; d2 = 200; d3 = 70; %Distances
a1 = 0.8; a2 = 0.15; a3 = 0.05; %power allocation coefficients
eta = 4; %path loss
% Generate Rayleigh fading channel for the three users
h1 = sqrt(d1^-eta)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
g1 = (abs(h1)).^2;
h2 = sqrt(d2^-eta)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
g2 = (abs(h2)).^2;
h3 = sqrt(d3^-eta)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
g3 = (abs(h3)).^2;
% Generate noise samples for the three users
n1 = sqrt(no)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
n2 = sqrt(no)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
n3 = sqrt(no)*(randn(N/2,1) + 1i*randn(N/2,1))/sqrt(2);
%Generate binary message data ((image)) for the three Users----------------
original1_image = imread('1.bmp');
[M1,N1]=size(original1_image);
[original1_Data,row_im, col_im, third_im] = image2data(original1_image, 2);%image 2 Data conversion
x1=0.1;
u1=4;
%Iterative200Second, achieve full chaotic state
for i1=1:200
x1=u1*x1*(1-x1);
end
%Generate a single-dimensional chaotic encryption sequence
A1=zeros(1,M1*N1); %generate1*Mn zero matrix
A1(1)=x1;
%Generate chaotic sequence
for i1=1:M1*N1-1
A1(i1+1)=u1*A1(i1)*(1-A1(i1));
end
%Normalized sequence
B1=uint8(255*A1); %Convert to 255 type of data
%Transforming into two-dimensional chaotic encryption sequence
Cipher1 =reshape(B1,M1,N1); %Reshape changes the shape of the specified matrix, but the number of elements does not change; here B is converted to M line, N column
Cipher_Data1 =image2data(Cipher1,2);
Encry1 =bitxor(original1_Data,Cipher_Data1); %Tone or operation encryption
%Encrypted1 = reshape (Encry1,N,1);
Encrypted1_image = data2image(Encry1, row_im, col_im, third_im, 2); %Data 2 image conversion
%--------------------------------------------------------------------------
original2_image = imread('2.bmp');
[M2,N2]=size(original2_image);
[original2_Data,row_im, col_im, third_im] = image2data(original2_image, 2);%image 2 Data conversion
x2=0.1;
u2=4;
%Iterative200Second, achieve full chaotic state
for i2=1:200
x2=u2*x2*(1-x2);
end
%Generate a single-dimensional chaotic encryption sequence
A2=zeros(1,M2*N2); %generate1*Mn zero matrix
A2(1)=x2;
%Generate chaotic sequence
for i2=1:M2*N2-1
A2(i2+1)=u2*A2(i2)*(1-A2(i2));
end
%Normalized sequence
B2=uint8(255*A2); %Convert to 255 type of data
%Transforming into two-dimensional chaotic encryption sequence
Cipher2=reshape(B2,M2,N2); %Reshape changes the shape of the specified matrix, but the number of elements does not change; here B is converted to M line, N columns
Cipher_Data2 =image2data(Cipher2,2);
Encry2 =bitxor(original2_Data ,Cipher_Data2); %Tone or operation encryption
%Encrypted2 = reshape (Encry2,N,1);
Encrypted2_image = data2image(Encry2, row_im, col_im, third_im, 2); %Data 2 image conversion
%--------------------------------------------------------------------------
original3_image = imread('3.bmp');
[M3,N3]=size(original3_image);
[original3_Data,row_im, col_im, third_im] = image2data(original3_image, 2);%image 2 Data conversion
x3=0.1;
u3=4;
%Iterative200Second, achieve full chaotic state
for i3=1:200
x3=u3*x3*(1-x3);
end
%Generate a single-dimensional chaotic encryption sequence
A3=zeros(1,M3*N3); %generate1*Mn zero matrix
A3(1)=x3;
%Generate chaotic sequence
for i3=1:M3*N3-1
A3(i3+1)=u3*A3(i3)*(1-A3(i3));
end
%Normalized sequence
B3=uint8(255*A3); %Convert to 255 type of data
Cipher3=reshape(B3,M3,N3); %Reshape changes the shape of the specified matrix, but the number of elements does not change; here B is converted to M line, N columns
Cipher_Data3 =image2data(Cipher3,2);
Encry3 =bitxor(original3_Data ,Cipher_Data3); %Tone or operation encryption
%Encrypted3 = reshape (Encry3,N,1);
Encrypted3_image = data2image(Encry3, row_im, col_im, third_im, 2); %Data 2 image conversion
%create QPSKModulator and QPSKDemodulator objects
QPSKmod = comm.QPSKModulator('BitInput',true);
QPSKdemod = comm.QPSKDemodulator('BitOutput',true);
%perform QPSK modulation
mod1 = step(QPSKmod,Encrypted1);
mod2 = step(QPSKmod,Encrypted2);
mod3 = step(QPSKmod,Encrypted3);
%Do superposition coding
x = sqrt(a1)*mod1 + sqrt(a2)*mod2 + sqrt(a3)*mod3 ;
for u = 1:length(Pt)
%received signals
y1 = sqrt(pt(u))*x.*h1 + n1;
y2 = sqrt(pt(u))*x.*h2 + n2;
y3 = sqrt(pt(u))*x.*h3 + n3;
%perform equalization
eq1 = y1./h1; %At user 1
eq2 = y2./h2; %At user 2
eq3 = y3./h3; %At user 3
%Demode at user1 (direct decoding)
dem1 = step(QPSKdemod, eq1);
demodulated1_image = data2image(dem1', row_im, col_im, third_im, 2); %Data 2 image conversion
%Demode at user2
dem12 = step(QPSKdemod, eq2); %Direct demodulation to get user1’s data
dem12_remod = step(QPSKmod, dem12); %Remodulation of user1’s data
rem2 = eq2 - sqrt(a1*pt(u))*dem12_remod; %SIC to remove user1’s data
dem2 = step(QPSKdemod, rem2); %direct demodulation of remaining signal
demodulated2_image = data2image(dem2', row_im, col_im, third_im, 2); %Data 2 image conversion
%Demode at user3
dem13 = step(QPSKdemod, eq3); %direct demodulation to get user1’s data
dem13_remod = step(QPSKmod, dem13); %Remodulation of user1’s data
rem31 = eq3 - sqrt(a1*pt(u))*dem13_remod; %SIC to remove user1’s data
dem23 = step(QPSKdemod, rem31); %direct demodulation of remaining signal to get user2’s data
dem23_remod = step(QPSKmod, dem23); %Remodulation of user2’s data
rem3 = rem31 - sqrt(a2*pt(u))*dem23_remod; %SIC to remove user2’s data
dem3 = step(QPSKdemod, rem3); %demodulate of remaining signal to get user3’s data
demodulated3_image = data2image(dem3', row_im, col_im, third_im, 2); %Data 2 image conversion
%BER calculation
ber1(u) = biterr(dem1, Encrypted1)/N;
ber2(u) = biterr(dem2, Encrypted2)/N;
ber3(u) = biterr(dem3, Encrypted3)/N;
end
Decrypted1=bitxor(dem1,Cipher1); %Decryption(XOR operation)
Decrypted1_image = data2image(Decrypted1', row_im, col_im, third_im, 2); %Data 2 image conversion
Decrypted2=bitxor(dem2,Cipher2); %Decryption(XOR operation)
Decrypted2_image = data2image(Decrypted2', row_im, col_im, third_im, 2); %Data 2 image conversion
Decrypted3=bitxor(dem3,Cipher3); %Decryption(XOR operation)
Decrypted3_image = data2image(Decrypted3', row_im, col_im, third_im, 2); %Data 2 image conversion
%--------------------------------------------------------------------------
figure(1)
subplot(1,4,1);
imshow(original1_image,[]);
subplot(1,4,2);
imshow(Encrypted1_image,[]);
subplot(1,4,3);
imshow(demodulated1_image,[]);
subplot(1,4,4);
imshow(Decrypted1_image,[]);
figure(2)
subplot(1,4,1);
imshow(original2_image,[]);
subplot(1,4,2);
imshow(Encrypted2_image,[]);
subplot(1,4,3);
imshow(demodulated2_image,[]);
subplot(1,4,4);
imshow(Decrypted2_image,[]);
figure(3)
subplot(1,4,1);
imshow(original3_image,[]);
subplot(1,4,2);
imshow(Encrypted3_image,[]);
subplot(1,4,3);
imshow(demodulated3_image,[]);
subplot(1,4,4);
imshow(Decrypted3_image,[]);
figure (4)
semilogy(Pt, ber1, 'b-o', 'linewidth', 2);
hold on; grid on ;
semilogy(Pt, ber2, 'r-s', 'linewidth', 2);
semilogy(Pt, ber3, 'k->', 'linewidth', 2);
xlabel('Transmit power (dBm)');
ylabel('BER');
legend('User 1 (Weakest user)', 'User 2', 'User 3 (Strongest user)');
Thanks in Advance.
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 11월 12일
Error using imread>get_full_filename (line 569)
File "2.bmp" does not exist.
Error in imread (line 371)
fullname = get_full_filename(filename);
Error in images_chaotic_NOMA_orig (line 60)
original2_image = imread('2.bmp');
Muhammad Abdulrazek
Muhammad Abdulrazek 2021년 11월 13일
편집: Muhammad Abdulrazek 2021년 11월 13일
2.bmp & 3.bmp are just a normal greyscale images
note : i used the same image i attached above
2.bmp & 3.bmp are a copy from 1.bmp

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by