Random substitution for QAM symbols

6 views (last 30 days)
YAHYA AL-MOLIKI
YAHYA AL-MOLIKI on 11 Nov 2020
Commented: Walter Roberson on 18 Nov 2020
Hi everyone, I want to do a random substitution for QAM symbols based on secret key or random vector.
For example, suppose 4-QAM modulation with the following substitution:
(00) is substituated to (10) ,
(01) is substituated to (00),
(10) is substituated to (11), and
(11) is substituated to (01).
Based on a secret key, the subsituation box is changed.
May you guide me how to do that in matlab with any M-ary QAM?
Thanks in advance.

Answers (2)

Walter Roberson
Walter Roberson on 11 Nov 2020
Edited: Walter Roberson on 11 Nov 2020
lookup = [1 0; 0 0; 1 1; 0 1]; %must be in numeric order
output = reshape(lookup([2 1] * reshape(VectorOfBits, 2, []) + 1, :).', 1, []);
The [2 1]* is converting from 2 bit binary into decimal. Then +1 to get a 1-based index, that is used to index into the lookup table of replacements. The rest has to do with arranging bits in the right order for processing.
There are other ways, such as
output = reshape(lookup(VectorOfBits(1:2:end)*2 + VectorOfBits(2:2:end) + 1,:).', 1, []);
and some of the work can be made easier if you make the lookup table column-oriented instead of row oriented.
  2 Comments
YAHYA AL-MOLIKI
YAHYA AL-MOLIKI on 18 Nov 2020
Edited: YAHYA AL-MOLIKI on 18 Nov 2020
Thank you Mr. Walter. Unfortuently, your code doesn't implement a corect subsistution.
Walter Roberson
Walter Roberson on 18 Nov 2020
I tested the code before I posted. Both versions work according to the requirements that were given.

Sign in to comment.


YAHYA AL-MOLIKI
YAHYA AL-MOLIKI on 18 Nov 2020
Edited: YAHYA AL-MOLIKI on 18 Nov 2020
I suggest the following code to implement substituation.
function y=substit(x,k)
y=zeros(length(x),2);
Rl=[0 0; 0 1; 1 0; 1 1];
Rm=randintrlv(Rl,k); %k is the secret key that is used to produce the substituation table.
for i=1:length(x)
switch binaryVectorToDecimal(x(i,:))
case 0
y(i,:)=Rm(1,:);
case 1
y(i,:)=Rm(2,:);
case 2
y(i,:)=Rm(3,:);
case 3
y(i,:)=Rm(4,:);
end
end
end
If there is another suggestion, you may share your codes.
  1 Comment
YAHYA AL-MOLIKI
YAHYA AL-MOLIKI on 18 Nov 2020
I suggest also the following code to implement inverse substituation as follows:
function y=invsubstit(x,k)
y=zeros(length(x),2);
Rl=[0 0; 0 1; 1 0; 1 1];
Rm=randintrlv(Rl,k);
Rmd=binaryVectorToDecimal(Rm);
for i=1:length(x)
switch binaryVectorToDecimal(x(i,:))
case 0
m=find(Rmd==0);
y(i,:)=Rl(m,:);
case 1
m=find(Rmd==1);
y(i,:)=Rl(m,:);
case 2
m=find(Rmd==2);
y(i,:)=Rl(m,:);
case 3
m=find(Rmd==3);
y(i,:)=Rl(m,:);
end
end
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!