How do I create an efficient code that will produce all combinations of a "N"x1 QPSK signal? ( example of all combinations of 4x1 QPSK & 2x1 QPSK signals are coded below )

2 visualizaciones (últimos 30 días)
%clear console; Remove all variables from memory; Close all figures
clc;clearvars;close all;
s1 = 0;
s2 = 0;
s3 = 0;
s4 = 0;
%All possible combinations a 4x1 QPSK DataSignal
Possi_4DataStreams = ones(4,256); %create a 4x256 matrix
%Constellations = [exp(1i*(pi/4)) exp(1i*(3.*pi/4)) exp(1i*(5.*pi/4)) exp(1i*(7.*pi/4))];
i=0;
for row1 = 1:4
if row1 == 1
s1 = exp(1i*(pi/4));
elseif row1 == 2
s1 = exp(1i*(3.*pi/4));
elseif row1 == 3
s1 = exp(1i*(5.*pi/4));
else
s1 = exp(1i*(7.*pi/4));
end
for row2 = 1:4
if row2 == 1
s2 = exp(1i*(pi/4));
elseif row2 == 2
s2 = exp(1i*(3.*pi/4));
elseif row2 == 3
s2 = exp(1i*(5.*pi/4));
else
s2 = exp(1i*(7.*pi/4));
end
for row3 = 1:4
if row3 == 1
s3 = exp(1i*(pi/4));
elseif row3 == 2
s3 = exp(1i*(3.*pi/4));
elseif row3 == 3
s3 = exp(1i*(5.*pi/4));
else
s3 = exp(1i*(7.*pi/4));
end
for row4 = 1:4
if row4 == 1
s4 = exp(1i*(pi/4));
elseif row4 == 2
s4 = exp(1i*(3.*pi/4));
elseif row4 == 3
s4 = exp(1i*(5.*pi/4));
else
s4 = exp(1i*(7.*pi/4));
end
i = i+1;
Possi_4DataStreams(:,i) = [s1;s2;s3;s4]; %i =1,2,3,4,...,256
end
end
end
end
Possi_4DataStreams %4x256 matrix. 256 possible combinations(4 constellations)
%All possible combinations a 2x1 QPSK DataSignal
Possi_2DataStreams = ones(2,4^2); %create a 4x256 matrix
%Constellations = [exp(1i*(pi/4)) exp(1i*(3.*pi/4)) exp(1i*(5.*pi/4)) exp(1i*(7.*pi/4))];
i=0;
for row1 = 1:4
if row1 == 1
s1 = exp(1i*(pi/4));
elseif row1 == 2
s1 = exp(1i*(3.*pi/4));
elseif row1 == 3
s1 = exp(1i*(5.*pi/4));
else
s1 = exp(1i*(7.*pi/4));
end
for row2 = 1:4
if row2 == 1
s2 = exp(1i*(pi/4));
elseif row2 == 2
s2 = exp(1i*(3.*pi/4));
elseif row2 == 3
s2 = exp(1i*(5.*pi/4));
else
s2 = exp(1i*(7.*pi/4));
end
i = i+1;
Possi_2DataStreams(:,i) = [s1;s2]; %i =1,2,3,4
end
end
Possi_2DataStreams %4x256 matrix. 256 possible combinations(4 constellations)

Respuestas (1)

Nihal
Nihal el 6 de Oct. de 2023
Hi Alvin,
I understand you want to generate all the combinations for nx1 QPSK signal and need your code to be more optimised.
We can utilize the "combvec" function to generate all possible combinations of the QPSK constellations for both the 4x1 and 2x1 data streams. This function takes the constellations as input arguments and returns a matrix with each column representing a unique combination.
Below is the sample code generating the same output using "combvec":
% Clear console; Remove all variables from memory; Close all figures
clc; clearvars; close all;
% Generate all possible combinations of a 4x1 QPSK Data Signal
constellations = exp(1i * [pi/4, 3*pi/4, 5*pi/4, 7*pi/4]);
Possi_4DataStreams = combvec(constellations, constellations, constellations, constellations);
% Generate all possible combinations of a 2x1 QPSK Data Signal
Possi_2DataStreams = combvec(constellations, constellations);
% Display the matrices
Possi_4DataStreams % 4x256 matrix. 256 possible combinations (4 constellations)
Possi_2DataStreams % 2x16 matrix. 16 possible combinations (4 constellations)
By using combvec instead of nested loops, we eliminate the need for explicit loop iterations and conditional statements, resulting in a more concise and efficient code.
The optimized code achieves the same outcome as the previous version while further improving efficiency and readability.
I would recommend this documentation for better understanding : https://www.mathworks.com/help/deeplearning/ref/combvec.html
I hope this information helped you

Community Treasure Hunt

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

Start Hunting!

Translated by