comparing values and using the results
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Stephen23
2018-11-9
编辑:Stephen23
2018-11-9
"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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!