WiFi信号量匹配算法

package Test;

import java.util.*;

public class Text2 {
public static void main(String[] args)
{
String[][] str = {{“0”,”2”,”-60”},{“0”,”4”,”-68”},{“0”,”6”,”-59”},{“0”,”8”,”-71”},{“0”,”10”,”-69”},{“0”,”12”,”-67”},
{“0”,”14”,”-66.5”},{“0”,”16”,”-69”},{“0”,”18”,”-57”},{“0”,”20”,”-59.5”},{“0”,”22”,”-65”},{“0”,”24”,”-60”},
{“0”,”26”,”-70.5”},{“0”,”28”,”-63.5”},{“0”,”30”,”-69.5”},{“0”,”32”,”-67”},{“0”,”34”,”-62”},{“0”,”36”,”-67”},
{“0”,”38”,”-70”},{“0”,”40”,”-74”},{“0”,”42”,”-72.5”},{“0”,”44”,”-68.5”},{“0”,”46”,”-68.5”},{“0”,”48”,”-71.5”},
{“0”,”50”,”-66”},{“0”,”52”,”-61”},{“0”,”54”,”-56”},{“0”,”56”,”-60.5”},{“0”,”58”,”-67.5”},{“0”,”60”,”-64.5”},
{“0”,”62”,”-73”},{“0”,”64”,”-74.5”},{“0”,”66”,”-71.5”},{“0”,”68”,”-63”},{“0”,”70”,”-59”},{“0”,”72”,”-60.5”},
{“0”,”74”,”-62.5”},{“0”,”76”,”-65”},{“0”,”78”,”-60”}}; //初始化采集的坐标及信号强度数据

    //str>>>对RSSI值选择排序
    for(int i = 0;i < str.length ;i++) {
        int k = i;
        for(int j = i + 1;j < str.length ;j++) {
            if(str[j][2].compareTo(str[k][2]) < 0) {
                k = j;
            }
        }
        String[] t = str[k];
        str[k] = str[i];
        str[i] = t;         
    }

    String[] strRssi = new String[str.length];
    for(int i = 0;i < str.length;i++) {
        strRssi[i] = new String(str[i][2]);
    }

    int index = Arrays.binarySearch(strRssi, "-61.5");
    float wr = Float.parseFloat("-61.5");

    System.out.println(index);                          //得到的下标

    if(index >= 0) {
        System.out.println(str[index][0]+","+str[index][1]);
    }
    else {
        index = -index - 1;
        float[] rs = new float[4];
        rs[0] = Float.parseFloat(str[index - 2][2]);
        rs[1] = Float.parseFloat(str[index - 1][2]);
        rs[2] = Float.parseFloat(str[index][2]);
        rs[3] = Float.parseFloat(str[index + 1][2]);

        double mix = 999;
        int location = 0;
        double dd = 0;

        for(int i = 0;i < 4;i++) {
            dd = Math.sqrt(Math.pow((wr - rs[i]), 2));
            if (mix - dd > 0.00001) {
                mix = dd;
                location = index - 2 + i;
            }
        }

        System.out.println(dd);            //欧式距离算法算出的值
        System.out.println(str[location][0] + "  " + str[location][1]);                //匹配到的坐标
    }

    //输出
    int i = 0;
    for(String a[]:str)
    {       
        System.out.print((i++) + "   ");
        for(String e:a)
        {               
            System.out.print(e);
            System.out.print("   ");
        }       
        System.out.println();
    }
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值