comparing values and using the results
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Stephen23
am 9 Nov. 2018
Bearbeitet: Stephen23
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!