无线传感器网络的时钟同步估计问题(Matlab代码实现)

👨‍🎓个人主页:研学社的博客    

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

随着无线传感器网络的快速发展,其应用领域也越来越广。在诸多的应用环境中都需要大量已同步的传感器节点通过协同作用执行一个分布式的任务,因此时钟同步成为了无线传感器网络众多应用的基础。​

📚2 运行结果

主函数部分代码:

% Code for Clock Synchronization for Wireless Sensor Networks
clc
clear all
close all
load("ClockSync.mat");
​
tx = tx_timestamps;
rx = rx_timestamps;
​
% Estimate of phi2 based on the Clock Synchronisation Equation
x = rx - tx - tau;
% (x has a Gaussian noise distribution (contributions from rx & tx measurement errors)
​
% Phi_2 Scaled as per Data set
phi_2s = phi_2 .* ones(K,trial,6);
phi2 = phi_2 .* ones(10,6);
p = phi_2.* ones(1,6);
​
% Estimated phi - Mean of timestamps of K messages with trials
phi_mean = squeeze(mean(x,2));
% Standard Deviation for K messages with trials
phi_std  = squeeze(std(x,1,2));
% Bias in Measurements for K messages with trials
phi_bias = (phi_mean - phi2).^2;
% Variance in Measurements for K messages
phi_var = (1/trial) * phi_std.^2;
​
% Calculated MSE & CRLB for the Dataset (average over K messages)
se = (x - phi_2s).^2 ;% Squared Error
mse_c = mean(squeeze(mean(se,2)));
crlb_c = mean(phi_var);
​
% Theoretical MSE & CRLB for the Dataset (average over K messages)
mse_t = mean(phi_var + phi_bias);
crlb_t = (1/trial) * noise_var;
​
% Phi : Estimates and Standard deviations
phi_mm = mean(phi_mean);
phi_sm = mean(phi_std);
 
% Plot of Theoretical & Estimated CRLB vs. Noise Variance 
figure
loglog(noise_var, crlb_t,'Marker', 'o')
%hold on
%loglog(noise_var, crlb_c,'Marker', 'x')
title('CRLB of \phi with noise variance','FontName', 'Times')
xlabel('Noise \sigma^2','FontName', 'Times')
ylabel('CRLB','FontName', 'Times')
legend('Theoretical CRLB') %, 'Calculated CRLB')
saveas(gca,['CRLB_Variance.png']);
​
% Plot of MSE vs. Noise Variance 
figure
loglog(noise_var, mse_t,'Marker', 'o')
hold on
loglog(noise_var, mse_c,'Marker', 'x')
title('MSE of \phi with noise variance','FontName', 'Times')
xlabel('Noise \sigma^2','FontName', 'Times')
ylabel('MSE','FontName', 'Times')
legend('Theoretical MSE', 'Calculated MSE')
saveas(gca,['MSE_Variance.png']);
​
% Plot of Phi_Estimate vs. Noise Variance 
figure
semilogx(noise_var, p,'Marker','o')
hold on
semilogx(noise_var, phi_mm,'Marker', 'x')
title('Estimate of \phi with noise variance','FontName', 'Times')
xlabel('Noise \sigma^2','FontName', 'Times')
ylabel('Estimate E[\phi]','FontName', 'Times')
legend('Reference', 'Numerical Estimate')
saveas(gca,['Estimate_Variance.png']);
​
% Plot of Data Sets with different noise variances
min_x = min(x,[],'all');
max_x = max(x,[],'all');
figure('Renderer', 'painters', 'Position', [10 10 1200 600])
t = tiledlayout(2,3,'TileSpacing','none');
for i = 1 : 6
    nexttile
    x1 = x(:,:,i);
    grid minor
    % pdf distribution for plotting Observed Data
    x_pdf(i,:) = linspace(min_x,max_x,K*trial);
    y_pdf(i,:) = normpdf(x_pdf(i,:), phi_mm(i), phi_sm(i));
    xline(phi_mm(i),'-','Estimate');
    hold on
    histogram(x1(:), 'Normalization', 'pdf', 'EdgeColor','k' ,'FaceColor' , 'none');
    hold on
    plot(x_pdf(i,:), y_pdf(i,:), 'color', 'b' , 'LineWidth',1);
    title(['E[\phi] for 10k MC run; Noise \sigma^2  = ', num2str(phi_sm(i))],'FontName', 'Times');
    xlabel('Distribution','FontName', 'Times');
    ylabel(['PDF'],'FontName', 'Times');
end

🎉3 参考文献

[1]田贤忠,龚婷,胡同森.基于指数时延的无线传感器网络时钟同步估计[J].小型微型计算机系统,2009,30(11):2186-2188.

部分理论引用网络文献,若有侵权联系博主删除。

🌈4 Matlab代码实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值