├── AddItem.m ├── ComSig.m ├── DelItem.m ├── GetSignal.m ├── LICENSE ├── MovItem.m ├── README.md ├── calibrate_device.m ├── compare_vector.m ├── data_process ├── calibrate_device.m ├── compare_vector.m ├── genarate_map.m ├── meandata.m ├── phase_link.m ├── phase_pre.m ├── readtagdata.m ├── signal_cre.m └── signal_cre_amp.m ├── exp_init.m ├── file_init.m ├── genarate_map.m ├── get_signal.m ├── global_function ├── Copy_2_of_get_obj_rssi.m ├── Copy_of_get_obj_rssi.m ├── get_obj_rssi.m └── get_obj_signal.m ├── init.m ├── preprocess.m ├── single_tracking ├── plot_single.m ├── single_init.m └── single_pos.m ├── temp.m ├── test.m └── total_entry.m /AddItem.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/AddItem.m -------------------------------------------------------------------------------- /ComSig.m: -------------------------------------------------------------------------------- 1 | function ret = ComSig(Siga,Sigb) 2 | global ANT_NUM TAG_NUM 3 | Thres = 0.1; 4 | diff = angle(Siga) - angle(Sigb); 5 | for index_ant=1:ANT_NUM 6 | for index_tag=1:TAG_NUM 7 | diff = abs(diff); 8 | diff = min(diff,2*pi-diff); 9 | end 10 | end 11 | DiffSum = sum(sum(diff)); 12 | if DiffSumpi); 15 | % delta_phase(id) = 2*pi - delta_phase(id); 16 | % delta_phase = delta_phase - min(delta_phase); 17 | % sum_phase = sum(delta_phase); 18 | % delta_map(i,j) = sum_phase; 19 | % end 20 | % end 21 | % [x_value,x] = min(delta_map,[],1); 22 | % [y_value,y] = min(min(delta_map,[],1),[],2); 23 | % pos_x = x(y); 24 | % pos_y = y; 25 | for i = 1:GRID_NUM 26 | for j = 1:GRID_NUM 27 | if(i == 72 && j == 40) 28 | reshape(phase_map(i,j,:),1,ANT_NUM*TAG_NUM) 29 | phase 30 | end 31 | phase_m = reshape(phase_map(i,j,:),1,ANT_NUM*TAG_NUM); 32 | delta_phase = mod(phase - phase_m,2*pi); 33 | weight = f_prob(min(abs(delta_phase),2*pi-abs(delta_phase))); 34 | sum_sig = sum(weight.*exp(1i*delta_phase)); 35 | % sum_sig = sum(exp(1i*delta_phase)); 36 | % sum_sig = sum(weight); 37 | delta_map(i,j) = abs(sum_sig); 38 | end 39 | end 40 | maxvalue = max(max(delta_map)); 41 | [x,y] = find(delta_map==max(max(delta_map))); 42 | x_grid = linspace(-0.5,0.5,GRID_NUM); 43 | y_grid = linspace(0.4,1.4,GRID_NUM); 44 | pos_x = x_grid(x); 45 | pos_y = y_grid(y); 46 | % figure(1); 47 | % plot(pos_x,pos_y,'*'); 48 | % hold on; 49 | % heatmap(x_grid,y_grid,delta_map.','GridVisible','off'); 50 | end 51 | function ret = f_prob(x) 52 | mean = 0; 53 | var = 0.4*sqrt(2); 54 | ret = 1/(var*sqrt(2*pi)).*exp(-(x-mean).^2./(4*var^2)); 55 | end 56 | -------------------------------------------------------------------------------- /data_process/calibrate_device.m: -------------------------------------------------------------------------------- 1 | function h_device = calibrate_device(ref_obj_signal) 2 | global SIG_REF 3 | h_device = ref_obj_signal./SIG_REF; 4 | % phase = angle(ref_obj_signal); 5 | end -------------------------------------------------------------------------------- /data_process/compare_vector.m: -------------------------------------------------------------------------------- 1 | function [pos_x,pos_y] = compare_vector(test_obj) 2 | load phase_map.mat phase_map 3 | global ANT_NUM TAG_NUM GRID_NUM 4 | GRID_NUM = 1001; 5 | phase = angle(test_obj); 6 | % len1 = length(phase_map(:,1,1)); 7 | % len2 = length(phase_map(1,:,1)); 8 | phase = reshape(phase,1,ANT_NUM*TAG_NUM); 9 | delta_map = zeros(GRID_NUM,GRID_NUM); 10 | % for i = 1:len1 11 | % for j = 1:len2 12 | % phase_m = reshape(phase_map(i,j,:),1,ANT_NUM*TAG_NUM); 13 | % delta_phase = mod(phase - phase_m,2*pi); 14 | % delta_phase = abs(delta_phase); 15 | % id = find(delta_phase>pi); 16 | % delta_phase(id) = 2*pi - delta_phase(id); 17 | % delta_phase = delta_phase - min(delta_phase); 18 | % sum_phase = sum(delta_phase); 19 | % delta_map(i,j) = sum_phase; 20 | % end 21 | % end 22 | % [x_value,x] = min(delta_map,[],1); 23 | % [y_value,y] = min(min(delta_map,[],1),[],2); 24 | % pos_x = x(y); 25 | % pos_y = y; 26 | for i = 1:GRID_NUM 27 | for j = 1:GRID_NUM 28 | phase_m = reshape(phase_map(i,j,:),1,ANT_NUM*TAG_NUM); 29 | delta_phase = mod(phase - phase_m,2*pi); 30 | weight = f_prob(min(abs(delta_phase),2*pi-abs(delta_phase))); 31 | sum_sig = sum(weight.*exp(1i*delta_phase)); 32 | delta_map(i,j) = abs(sum_sig); 33 | end 34 | end 35 | [x,y] = find(delta_map==max(max(delta_map))); 36 | x_grid = linspace(-0.5,0.5,GRID_NUM); 37 | y_grid = linspace(0.4,1.4,GRID_NUM); 38 | pos_x = x_grid(x); 39 | pos_y = y_grid(y); 40 | heatmap(pos_x,pos_y,delta_map.','GridVisible','off'); 41 | hold on; 42 | plot(pos_x,pos_y,'*'); 43 | end 44 | function ret = f_prob(x) 45 | mean = 0; 46 | var = 0.4*sqrt(2); 47 | ret = 1/(var*sqrt(2*pi)).*exp(-(x-mean).^2./(4*var^2)); 48 | end 49 | -------------------------------------------------------------------------------- /data_process/genarate_map.m: -------------------------------------------------------------------------------- 1 | ax = [0 0.9]; 2 | ay = [0 0.9]; 3 | ant_h = 0.51; 4 | tag_h = 0.14; 5 | lambda = 0.32564; 6 | grid_num = 1001; 7 | tx = [-0.45 -0.3 -0.15 0 0.15 0.3 0.45 0.5 0.5 0.5 0.5 0.5 0.5 0.5]; 8 | ty = [0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.45 0.6 0.75 0.9 1.05 1.2 1.35]; 9 | x = linspace(-0.5,0.5,grid_num); 10 | y = linspace(0.4,1.4,grid_num); 11 | phase_map = zeros(grid_num,grid_num,28); 12 | for index_ant = 1:2 13 | for index_tag = 1:14 14 | for index_x = 1:grid_num 15 | for index_y = 1:grid_num 16 | dis_a = sqrt((x(index_x)-ax(index_ant))^2 + (y(index_y)-ay(index_ant))^2+ant_h^2); 17 | dis_t = sqrt((x(index_x)-tx(index_tag))^2 + (y(index_y)-ty(index_tag))^2+tag_h^2); 18 | phase = mod((dis_a + dis_t)*2*pi/lambda,2*pi); 19 | phase_map(index_x,index_y,(index_ant-1)*14+index_tag) = phase; 20 | end 21 | end 22 | end 23 | end 24 | heatmap(phase_map(:,:,1)); 25 | save phase_map.mat phase_map 26 | -------------------------------------------------------------------------------- /data_process/meandata.m: -------------------------------------------------------------------------------- 1 | function [mean_phase,mean_rssi] = meandata(filename) 2 | %% 读取数据 3 | [~,phase,rssi,time,~] = readtagdata(filename); 4 | count = length(phase); 5 | %% 数据预处理 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | phase = phase_pre(phase,count); 8 | mean_phase = mean(phase); 9 | mean_rssi = mean(rssi); 10 | end -------------------------------------------------------------------------------- /data_process/phase_link.m: -------------------------------------------------------------------------------- 1 | function phase =phase_link(phase,count) 2 | for i= 2:count 3 | while phase(i)-phase(i-1)<-2 4 | phase(i) = phase(i) + 2*pi; 5 | end 6 | while phase(i)-phase(i-1)>2 7 | phase(i) = phase(i) - 2*pi; 8 | end 9 | end -------------------------------------------------------------------------------- /data_process/phase_pre.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/data_process/phase_pre.m -------------------------------------------------------------------------------- /data_process/readtagdata.m: -------------------------------------------------------------------------------- 1 | function [tid,phase,rssi,time,antport] = readtagdata(filename) 2 | 3 | 4 | %% file proc 5 | f=fopen(filename,'r'); 6 | narginchk(1,1); 7 | data = fscanf(f,'%*s %lf %lf %lf %lf %*lf',[4,inf]); 8 | data = data'; 9 | tid = filename; 10 | phase = data(:,1); 11 | rssi = data(:,2); 12 | time = data(:,3); 13 | antport = data(:,4); 14 | init_time = time(1); 15 | %% change the unit of time 16 | time = (time-init_time)./1000000; 17 | fclose(f); 18 | end -------------------------------------------------------------------------------- /data_process/signal_cre.m: -------------------------------------------------------------------------------- 1 | function [signal,amp] = signal_cre(phase,rssi) 2 | % amp(t) = 10^sqrt((rssi(t)+100)/1000); 3 | amp = 10.^(rssi./10); 4 | signal = amp.*exp(-1i.*phase); 5 | end -------------------------------------------------------------------------------- /data_process/signal_cre_amp.m: -------------------------------------------------------------------------------- 1 | function [signal] = signal_cre_amp(amp,phase) 2 | 3 | signal = amp.*exp(-1i.*phase); 4 | 5 | end -------------------------------------------------------------------------------- /exp_init.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/exp_init.m -------------------------------------------------------------------------------- /file_init.m: -------------------------------------------------------------------------------- 1 | function file_init() 2 | global TESTNAME ENVNAME REFNAME ENV HDEVICE ... 3 | OBJNUM HISLIST 4 | ENVNAME = 'env'; 5 | REFNAME = 'reference1'; 6 | TESTNAME = 'test1'; 7 | ENV = GetSignal(ENVNAME); 8 | ref_signal = GetSignal(REFNAME); 9 | ref_obj = ref_signal - ENV; 10 | HDEVICE = calibrate_device(ref_obj); 11 | %% init some value 12 | OBJNUM = 0; 13 | HISLIST = ''; 14 | end -------------------------------------------------------------------------------- /genarate_map.m: -------------------------------------------------------------------------------- 1 | global PAX PAY PTX PTY GRID_X GRID_Y ANT_HEI TAG_HEI LAMBDAS GRID_NUM ANT_NUM TAG_NUM 2 | exp_init(); 3 | 4 | phase_map = zeros(GRID_NUM,GRID_NUM,28); 5 | for index_ant = 1:ANT_NUM 6 | for index_tag = 1:TAG_NUM 7 | for index_x = 1:GRID_NUM 8 | for index_y = 1:GRID_NUM 9 | dis_a = sqrt((GRID_X(index_x)-PAX(index_ant))^2 + (GRID_Y(index_y)-PAY(index_ant))^2+ANT_HEI^2); 10 | dis_t = sqrt((GRID_X(index_x)-PTX(index_tag))^2 + (GRID_Y(index_y)-PTY(index_tag))^2+TAG_HEI^2); 11 | phase = mod((dis_a + dis_t)*2*pi/LAMBDAS,2*pi); 12 | phase_map(index_x,index_y,(index_ant-1)*TAG_NUM+index_tag) = phase; 13 | end 14 | end 15 | end 16 | end 17 | % heatmap(phase_map(:,:,1)); 18 | save phase_map.mat phase_map 19 | -------------------------------------------------------------------------------- /get_signal.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/get_signal.m -------------------------------------------------------------------------------- /global_function/Copy_2_of_get_obj_rssi.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/global_function/Copy_2_of_get_obj_rssi.m -------------------------------------------------------------------------------- /global_function/Copy_of_get_obj_rssi.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/global_function/Copy_of_get_obj_rssi.m -------------------------------------------------------------------------------- /global_function/get_obj_rssi.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/global_function/get_obj_rssi.m -------------------------------------------------------------------------------- /global_function/get_obj_signal.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/global_function/get_obj_signal.m -------------------------------------------------------------------------------- /init.m: -------------------------------------------------------------------------------- 1 | exp_init(); 2 | file_init(); -------------------------------------------------------------------------------- /preprocess.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/preprocess.m -------------------------------------------------------------------------------- /single_tracking/plot_single.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/single_tracking/plot_single.m -------------------------------------------------------------------------------- /single_tracking/single_init.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/single_tracking/single_init.m -------------------------------------------------------------------------------- /single_tracking/single_pos.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/single_tracking/single_pos.m -------------------------------------------------------------------------------- /temp.m: -------------------------------------------------------------------------------- 1 | global ANT_NUM TAG_NUM GRID_NUM 2 | load phase_map.mat phase_map 3 | init; 4 | for i = 1:GRID_NUM 5 | for j = 1:GRID_NUM 6 | phase_m = reshape(b(i,j,:),1,ANT_NUM*TAG_NUM); 7 | weight = f_prob(min(abs(phase_m),2*pi-abs(phase_m))); 8 | sum_sig = sum(weight.*exp(1i*phase_m)); 9 | % sum_sig = sum(exp(1i*delta_phase)); 10 | % sum_sig = sum(weight); 11 | delta_map(i,j) = abs(sum_sig); 12 | end 13 | end 14 | 15 | maxvalue = max(max(delta_map)); 16 | [x,y] = find(delta_map==max(max(delta_map))); 17 | x_grid = linspace(-0.5,0.5,GRID_NUM); 18 | y_grid = linspace(0.4,1.4,GRID_NUM); 19 | pos_x = x_grid(x); 20 | pos_y = y_grid(y); 21 | 22 | heatmap(x_grid,y_grid,delta_map.','GridVisible','off'); 23 | 24 | function ret = f_prob(x) 25 | mean = 0; 26 | var = 0.4*sqrt(2); 27 | ret = 1/(var*sqrt(2*pi)).*exp(-(x-mean).^2./(4*var^2)); 28 | end -------------------------------------------------------------------------------- /test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomy/RFID-Localization/3b6f21872a883ca1a4f76202c83c8df6b0d14750/test.m -------------------------------------------------------------------------------- /total_entry.m: -------------------------------------------------------------------------------- 1 | global TESTNAME ENV OBJNUM HISLIST 2 | TESTNAME = 'test1'; 3 | now_sig = GetSignal(TESTNAME); 4 | [Addx,Addy,Addmax,Addobj]=AddItem(now_sig); 5 | [Delnum,Delmax]=DelItem(now_sig); 6 | [Movx,Movy,Movnum,Movmax,Movobj]=MovItem(now_sig); 7 | if(Addmax>Delmax && Addmax>Movmax) 8 | OBJNUM = OBJNUM + 1; 9 | HISLIST(OBJNUM).obj = Addobj; 10 | HISLIST(OBJNUM).env = now_sig; 11 | HISLIST(OBJNUM).pos = [Addx Addy]; 12 | end 13 | if(Delmax>Addmax && Delmax>Movmax) 14 | OBJNUM = OBJNUM - 1; 15 | HISLIST(Delnum)=''; 16 | if(Delnum == 1) 17 | env = ENV; 18 | else 19 | env = HISLIST(Delnum-1).env; 20 | end 21 | for index_item = Delnum:OBJNUM 22 | env = env + HISLIST(Delnum).obj; 23 | HISLIST(Delnum).env = env; 24 | end 25 | end 26 | if(Movmax>Delmax && Movmax>Addmax) 27 | HISLIST(Movnum).pos=[Movx Movy]; 28 | HISLIST(Movnum).obj=Movobj; 29 | if(Movnum == 1) 30 | env = ENV; 31 | else 32 | env = HISLIST(Movnum-1).env; 33 | end 34 | for index_item = Movnum:OBJNUM 35 | env = env + HISLIST(Movnum).obj; 36 | HISLIST(Movnum).env = env; 37 | end 38 | end --------------------------------------------------------------------------------