fingerprint_sim中存放20m*15m房间内6个AP的指纹数据库, RSSI_fp中存放6个AP100组测试数据的RSSI,p_true中存放100组测试数据的真实位置,进行高斯滤波,matlab仿真代码
时间: 2024-05-27 07:11:31 浏览: 163
% Load fingerprint database
load('fingerprint_sim.mat');
% Load test data
load('RSSI_fp.mat');
load('p_true.mat');
% Set parameters for Gaussian filtering
sigma = 2; % standard deviation (in meters)
window_size = 7; % window size (odd number)
% Initialize variables
n_test = size(RSSI_fp, 1);
p_estimate = zeros(n_test, 2);
% Iterate over test data
for i = 1:n_test
% Get RSSI measurements for current test sample
rssi_sample = RSSI_fp(i, :);
% Calculate distances to each AP using RSSI measurements and fingerprint database
d_sample = zeros(1, 6);
for j = 1:6
d_sample(j) = norm(rssi_sample - fingerprint_sim(j, :));
end
% Use distances to estimate position using Gaussian filtering
weights = exp(-0.5 * (d_sample / sigma).^2);
weights = weights / sum(weights);
p_estimate(i, :) = weights * p_true;
% Print progress
if mod(i, 10) == 0
fprintf('Processed %d test samples\n', i);
end
end
% Calculate mean error
error = sqrt(sum((p_estimate - p_true).^2, 2));
mean_error = mean(error);
% Plot results
figure;
plot(p_true(:, 1), p_true(:, 2), 'ro', 'MarkerSize', 5);
hold on;
plot(p_estimate(:, 1), p_estimate(:, 2), 'bx', 'MarkerSize', 5);
legend('True position', 'Estimated position');
title(sprintf('Gaussian filtering (sigma = %d, window size = %d)\nMean error = %.2f meters', sigma, window_size, mean_error));
xlabel('X position (meters)');
ylabel('Y position (meters)');
阅读全文