简体   繁体   中英

Bit Error Rate using Test Data

I have the below code. I want to find the bit error rate considering the clustered data as a trained data and send a test data. Can I do that with this code? I appreciate your active support.

clear all;  
clc;

T=[ 2+2*i 2-2*i -2+2*i -2-2*i];

A=randn(150,2)+2*ones(150,2); C=randn(150,2)-2*ones(150,2); B=randn(150,2)+2*ones(150,2); 
F=randn(150,2)-2*ones(150,2); D=randn(150,2)+2*ones(150,2); G=randn(150,2)-2*ones(150,2);     
E=randn(150,2)+2*ones(150,2); H=randn(150,2)-2*ones(150,2);

X = [A; B; D; C; F; E; G; H];

[idx, centroids] = kmeans(X, 4, 'Replicates', 20);

x = X(:,1); y = X(:,2);

figure; 
colors = 'rgbk'; 
[X,Y] = meshgrid(-5:0.05:5, -5:0.05:5);
X = X(:); 
Y = Y(:); 
figure; hold on; 

for idx = 1 : numel(X) 
   [dummy,ind] = min(sum(bsxfun(@minus, [X(idx) Y(idx)], centroids).^2, 2)); 
   plot(X(idx), Y(idx), [colors(ind), '.']); 
end

OK, now your question is more clear. I didn't understand what you meant in your other post. Alright, it looks like your T is your transmission alphabet. Be advised that the clusters that you get through k -means will probably not be the same as those from your transmission alphabet, so you're going to have to figure out which centroids are the closest from to your transmission alphabet. We can do that with the following code:

gt = zeros(1,4);
for idx = 1 : 4
    [dummy,gt(idx)] = min(sum(bsxfun(@minus, [real(T(idx)), imag(T(idx))], centroids).^2, 2));
end

gt will contain which symbol in your alphabet matches which cluster centroid in your data. For your results to be reproducible, I set the random seed generator to 1234 (ie rng(1234); ) then ran your code. It gave me the following for gt :

gt =

     4     2     3     1

Simply put, each element in gt tells you which symbol in T matches up with what centroid in centroids . Therefore, gt(1) = 4 means that centroid #1 got matched to the 4th symbol in your transmission alphabet, gt(2) = 2 means that centroid #2 got matched to the 2nd symbol in your alphabet and so on.

As such, given your test sequence that is composed of the alphabet in T , simply create your test sequence, keeping in mind what gt is. Therefore, you could do something like this:

rng(1234);
rand_ind = randi(4, 10, 1);
test_sequence = T(rand_ind);
gt_labels = gt(rand_ind);

The above code will generate a random integer sequence from 1 to 4 and there will be 10 of these numbers. I then use this to create a random test sequence using the alphabet from T . gt_labels will also contain what the actual labels of each symbol is with respect to the cluster centroids. Now, let's split this up into real and imaginary components and add some noise.

x = real(test_sequence).*randn(1, 10);
y = imag(test_sequence).*randn(1, 10);

This noise... let's say... this was added as you sent this through a communication channel. Now that we have our real and imaginary components, let's figure out how this sequence was classified as. We would use x and y and determine the cluster that each point belongs to:

labels = zeros(1, 10);
for idx = 1 : 10
    [dummy,labels(idx)] = min(sum(bsxfun(@minus, [x(idx), y(idx)], centroids).^2, 2));
end

labels will contain how your clustering mechanism classified each point as. I got:

labels =

     1     4     3     1     4     1     2     2     2     3

Similarly, this is the labelling that was assigned to your test sequence before transmission:

gt_labels =

     4     3     2     1     1     2     2     1     1     1

As such, the BER (bit error rate) is simply counting the number of mismatches and dividing by the total sequence. You would multiply this by 100% to get this in percentage instead of a proportion. Therefore:

BER = sum(labels ~= gt_labels) / 10 * 100;

BER = 

80

As such, we have a BER of 80%.... not very good!


This should be enough to get you started. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM