comparing values and using the results

3 views (last 30 days)
Panda Girl
Panda Girl on 9 Nov 2018
Commented: Panda Girl on 9 Nov 2018
I am working on a program of spread spectrum demonstration and i have data from 3 source depending upton the number of 1's in each data i have the strongest signal and weaker signals.
tag0 = 0;
sco = [1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0];
out0 = xor(tag0,sco)
out0 =
1×16 logical array
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
>> tag1 = 1;
sc1 = [1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0];
out1 = xor(tag1,sc1)
out1 =
1×16 logical array
0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1
>> tag2 = 1;
sc2 = [1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0];
out2 = xor(tag2,sc2)
out2 =
1×16 logical array
0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1
despread_x0_usingsco = xor(x_0,sco)
despread_x0_usingsco =
1×16 logical array
1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1
>> despread_x1_usingsc1 = xor(x_1,sc1)
despread_x1_usingsc1 =
1×16 logical array
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>> despread_x2_usingsc2 = xor(x_2,sc2)
despread_x2_usingsc2 =
1×16 logical array
1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1
tag0_data = despread_x0_usingsco;
tag1_data = despread_x1_usingsc1;
tag2_data = despread_x2_usingsc2;
count_tag0 = nnz(tag0_data == 1)
count_tag0 =
8
>> count_tag1 = nnz(tag1_data == 1)
count_tag1 =
16
>> count_tag2 = nnz(tag2_data == 1)
count_tag2 =
8
>> if count_tag0 > 8
then count_tag0 = 1
else
count_tag0 = 0;
end
>> if count_tag1 > 8
count_tag1 = 1;
else
count_tag1 = 0;
end
>> if count_tag2 > 8
count_tag2 = 1;
else
count_tag2 = 0;
end
>> reconstructed_spreaddata_code2_sc1 = xor(count_tag1,sc1)
Looking at the above code its clear that despread_s1_usingsc1 is the strongest because it has better consistency of 1's in it. how will I compare count_tag0 , count_tag1 , count_tag2 in order to determine which despread code is the strongest. The current method flow that I am following after these statement(eg : despread_x0_usingsco = xor(x_0,sco)) is to count the number of one's in despread_x0_usingsc0\1\2 and then determining which value is the highest. how will i write a code that will automatically compare and give a result saying a particular code is strongest

Answers (1)

Stephen23
Stephen23 on 9 Nov 2018
Edited: Stephen23 on 9 Nov 2018
"how will i write a code that will automatically compare and give a result saying a particular code is strongest"
By changing your approach to writing code. Instead of using lots of numbered variable names (which is a sign that you are doing something wrong) you should just put all of your data into arrays. Then you can easily use simple and efficient tools like sum and max to identify which row represents the best solution. Something like this:
>> xM = randi(0:1,3,16) % fake data (you did not provide this)
xM =
0 1 0 1 1 0 0 1 0 0 0 0 1 1 0 1
0 1 1 0 0 0 0 1 1 0 1 1 0 1 0 1
0 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0
>> tagV = [0;1;1];
>> scoM = [1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0;1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0;1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0];
>> outM = xor(tagV,scoM);
>> desp = xor(xM,scoM);
>> totV = sum(desp,2)
totV =
11
6
7
>> [val,idx] = max(totV)
val = 11
idx = 1
>> scoM(idx,:)
ans =
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
  2 Comments
Panda Girl
Panda Girl on 9 Nov 2018
  • Thank you so much for your answer @Stephen Cobeldick. I really appreciate your help. I tried running this code it's working properly the way i wanted but, I have certain doubts.
  • The reconstructed signal syntax line that i have in this particular code works in the following way
  • it is basically xor of two things.
  • 1. a spreading code whose despread has more number of 1's
  • and the value (i.e either o' or 1) that means if for example if desp of 2 row is all 1 its output will be 1 and rest it will be 0,0
reconstruct = xor(scom,row2) (i.e its spreading code and the output)
Panda Girl
Panda Girl on 9 Nov 2018
is it okay to use the if condition to get the output result for all desp as above mentioned in the code or how should I put all the ouput of desp in row of different matrix and then try to xor the strongest version and its output. kindly suggest

Sign in to comment.

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!