【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)

news2024/9/23 1:24:07

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

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

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

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

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码及数据


💥1 概述

在本文中,MATLAB 用于通过与使用 XBee 系列 2 模块构建的温度传感器无线网络进行交互,连续监控整个公寓的温度。每个XBee边缘节点从多个温度传感器读取模拟电压(与温度成线性比例)。读数通过协调器XBee模块传输回MATLAB。本文说明了如何操作、获取和分析来自连接到多个 XBee 边缘节点的多个传感器网络的数据。数据采集时间从数小时到数天不等,以帮助设计和构建智能恒温器系统。

📚2 运行结果

 

 

 

 

 

 

 

 

 

 

 

 

 部分代码:

%% Overview of Data
% As I mentioned in a previous post, I collected the temperature every two
% minutes over the course of 9 days. I placed 14 sensors in my apartment: 9
% located inside, 2 located outside, and 3 located in radiators. The data
% is stored in the file <../twoweekstemplog.txt |twoweekstemplog.txt|>.

[tempF,ts,location,lineSpecs] = XBeeReadLog('twoweekstemplog.txt',60);
tempF = calibrateTemperatures(tempF);
plotTemps(ts,tempF,location,lineSpecs)
legend('off')
xlabel('Date')
title('All Data Overview')

%%
% _Figure 1: All temperature data from a 9 day period._
%
% That graph is a bit too cluttered to be very meaningful. Let me remove
% the radiator data and the legend and see if that helps.

notradiator = [1 2 3 5 6 7 8 9 10 12 13];
plotTemps(ts,tempF(:,notradiator),location(notradiator),lineSpecs(notradiator,:))
legend('off')
xlabel('Date')
title('All Inside and Outside Temperature Data')

%%
% _Figure 2: Just inside and outside temperature data, with radiator data removed._
%
% Now I can see some places where one of the outdoor temperature sensors
% (blue line) gave erroneous data, so let's remove those data points. This
% data was collected in March in Massachusetts, so I can safely assume the
% outdoor temperature never reached 80 F. I replaced any values above 80 F
% with |NaN| (not-a-number) so they are ignored in further analysis.

outside = [3 10];
outsideTemps = tempF(:,outside);
toohot = outsideTemps>80;
outsideTemps(toohot) = NaN;
tempF(:,outside) = outsideTemps;

plotTemps(ts,tempF(:,notradiator),location(notradiator),lineSpecs(notradiator,:))
legend('off')
xlabel('Date')
title('Cleaned-up Inside and Outside Temperature Data')

%%
% _Figure 3: Inside and outside temperature data with erroneous data removed._
%
% I'll also remove all but one inside sensor per room, and give the
% remaining sensors shorter names, to keep the graph from getting too
% cluttered.

show = [1 5 9 12 10 3];
location(show) = ...
    {'Bedroom','Kitchen','Living Room','Office','Front Porch','Side Yard'}';

plotTemps(ts,tempF(:,show),location(show),lineSpecs(show,:))
ylim([0 90])
legend('Location','SouthEast')
xlabel('Date')
title('Summary of Temperature Data')

%%
% _Figure 4: Summary of temperature data with only one inside temperature
% sensor per room with outside temperatures._
%
% That looks much better. This data was collected over the course of 9
% days, and the first thing that stands out to me is the periodic outdoor
% temperature, which peaks every day at around noon. I also notice a sharp
% spike in the side yard (green) temperature on most days. My front porch
% (blue) is located on the north side of my apartment, and does not get
% much sun. My side yard is on the east side of my apartment, and that
% spike probably corresponds to when the sun hits the sensor from between
% my apartment and the building next door.

%% When do my radiators start to heat up?
% The radiator temperature can be used to measure how long it takes for my
% boiler and radiators to warm up after the heat has been turned on. Let's
% take a look at 1 day of data from the living room radiator:

% Grab the Living Room Radiator Temperature (index 11) from the |tempF| matrix.
radiatorTemp = tempF(:,11);

% Fill in any missing values:
validts = ts(~isnan(radiatorTemp));
validtemp = radiatorTemp(~isnan(radiatorTemp));
nants = ts(isnan(radiatorTemp));
radiatorTemp(isnan(radiatorTemp)) = interp1(validts,validtemp,nants);

% Plot the data
oneday = [ts(1) ts(1)+1];
figure
plot(ts,radiatorTemp,'k.-')
xlim(oneday)
xlabel('Time')
ylabel('Radiator Temperature (\circF)')
title('Living Room Radiator Temperature')
datetick('keeplimits')
snapnow

%%
% _Figure 5: One day of temperature data from the living room radiator._
%
% As expected, I see a sharp rise in the radiator temperature, followed by
% a short leveling off (when the radiator temperature maxes out the
% temperature sensor), and finally a gradual cooling of the radiator. Let
% me superimpose the rate of change in temperature onto the plot.

tempChange = diff([NaN; radiatorTemp]);

hold on
plot(ts,tempChange,'b.-')
legend({'Temperature', 'Temperature Change'},'Location','Best')

%%
% _Figure 6: One day of data from the living room radiator with temperature change._
%
% It looks like I can detect those peaks by looking for large jumps in the
% temperature. After some trial and error, I settled on three criteria to
% identify when the heat comes on:
%
% # Change in temperature greater than four times the previous change in temperature.
% # Change in temperature of more than 1 degree F.
% # Keep the first in a sequence of matching points (remove doubles)

fourtimes = [tempChange(2:end)>abs(4*tempChange(1:end-1)); false];
greaterthanone = [tempChange(2:end)>1; false];
heaton = fourtimes & greaterthanone;
doubles = [false; heaton(2:end) & heaton(1:end-1)];
heaton(doubles) = false;

%%
% Let's see how well I detected those peaks by superimposing red dots over
% the times I detected.

figure
plot(ts,radiatorTemp,'k.-')
hold on
plot(ts(heaton),radiatorTemp(heaton),'r.','MarkerSize',20)
xlim(oneday);
datetick('keeplimits')
xlabel('Time')
ylabel('Radiator Temperature (\circF)')
title('Heat On Event Detection')
legend({'Temperature', 'Heat On Event'},'Location','Best')

%%
% _Figure 7: Radiator temperature with heating events marked with red dots._
%
% Looks pretty good, which means now I have a list of all the times that
% the heat came on in my apartment.
heatontimes = ts(heaton);

%% How long does it take for my heat to turn on?
% I currently have a programmable 5/2 thermostat, which means I can set
% one program for weekdays (Monday through Friday) and one program for both
% Saturday and Sunday. I know my thermostat is set to go down to 62 at
% night, and back up to 68 at 6:15am Monday through Friday and 10:00am on
% Saturday and Sunday. I used that knowledge to determine how long after my
% thermostat activates that my radiators warm up.
%
% I started by creating a vector of all the days in the test period. I
% removed Monday because I manually turned on the thermostat early that day.
mornings = floor(min(ts)):floor(max(ts));
mornings(2) = []; % Remove Monday

%%
% Then I added either 6:15am or 10:00am to each day depending on whether it
% was a weekday or a weekend.
isweekend = weekday(mornings) == 1 | weekday(mornings) == 7;
mornings(isweekend) = mornings(isweekend)+10/24; % 10:00 AM
mornings(~isweekend) = mornings(~isweekend)+6.25/24; % 6:15 AM

%%
% Next I looked for the first time the heat came on after the programmed
% time each morning.
heatontimes_mat = repmat(heatontimes,1,length(mornings));
mornings_mat = repmat(mornings,length(heatontimes),1);
timelag = heatontimes_mat - mornings_mat;
timelag(timelag<=0) = NaN;

plot(ts,radiatorTemp,'k.-')
hold on
plot(heatontimes,heatontemp,'r.','MarkerSize',20)
plot(heatontimes(heatind),heatontemp(heatind),'bo','MarkerSize',10)
plot([mornings;mornings],repmat(ylim',1,length(mornings)),'b-');
xlim(onemorning);
datetick('keeplimits')
xlabel('Time')
ylabel('Radiator Temperature (\circF)')
title('Detection of Scheduled Heat On Events')
legend({'Temperature', 'Heat On Event', 'Scheduled Heat On Event',...
    'Scheduled Event'},'Location','Best')

%%
% _Figure 8: Six hours of radiator data, with a blue line indicating when
% the thermostat turned on in the morning, and blue circle indicating the
% corresponding heat on event of the radiator._
%
% Let's look at a histogram of those delays:
figure
hist(delay,min(delay):max(delay))
xlabel('Minutes')
ylabel('Frequency')
title('How long before the radiator starts to warm up?')

%%
% _Figure 9: Histogram showing delay between thermostat activation and the
% radiators starting to warm up._
%
% It looks like the delay between the thermostat coming on in the morning
% and the radiators starting to warming up can range from 7 minutes to as
% high as 24 minutes, but on average this delay is around 12-13 minutes.
heatondelay = 12;

%% How long does it take for the radiators to warm up?
% Once the radiators start to warm up, it takes a few minutes for them to
% reach full temperature. Let's look at how long this takes. I'll look for
% times when the radiator temperature first maxes out the temperature
% sensor after having been below the maximum for at least 10 minutes (5
% samples).

maxtemp = max(radiatorTemp);
radiatorhot = radiatorTemp(6:end)==maxtemp & ...
    radiatorTemp(1:end-5)<maxtemp &...
    radiatorTemp(2:end-4)<maxtemp &...
    radiatorTemp(3:end-3)<maxtemp &...
    radiatorTemp(4:end-2)<maxtemp &...
    radiatorTemp(5:end-1)<maxtemp;
radiatorhot = [false(5,1); radiatorhot];
radiatorhottimes = ts(radiatorhot);
%
% Now I'll match the |radiatorhottimes| to the |heatontimes| using the same
% technique I used above.
radiatorhottimes_mat = repmat(radiatorhottimes',length(heatontimes),1);
heatontimes_mat = repmat(heatontimes,1,length(radiatorhottimes));
timelag = radiatorhottimes_mat - heatontimes_mat;
timelag(timelag<=0) = NaN;
[delay, foundmatch] = min(timelag);
delay = round(delay*24*60);

%%
% Let's look at a histogram of those delays:
figure
hist(delay,min(delay):2:max(delay))
xlabel('Minutes');
ylabel('Frequency')
title('How long does the radiator take to warm up?')

%%
% _Figure 11: Histogram showing time required for the radiators to warm up._
%
% It looks like the radiators take between 4 and 8 minutes from when they
% start to warm up until they are at full temperature.
radiatorheatdelay = 6;

%%
% Later on in my analysis, I will only want to use times that the heat came
%
% Although it isn't perfect, it looks close to a linear relationship. Since
% I am interested in the time it takes to reach the desired temperature
% (what could be considered the "specific heat capacity" of the room), let
% me replot the data with time on the y-axis and temperature on the x-axis
% (swapping the axes from the previous figure). I'll also plot the data as
% individual points instead of lines, because that is how the data is going
% to be fed into |polyfit| later.

% Remove temperatures occuring before the minimum temperature.
segmentTempsShifted(segmentTimesShifted<0) = NaN;

figure
h1 = plot(segmentTempsShifted',segmentTimesShifted','k.');
xlabel('Temperature Increase (\circF)')
ylabel('Minutes since minimum temperature')
title('Time to Heat Living Room')
snapnow

%%
% _Figure 17: The time it takes to heat the living room (axes flipped from
% Figure 16)._
%
% Now let me fit a line to the data so I can get an equation for the time
% it takes to heat the living room.

%%
% First I collect all the time and temperature data into a single column
% vector and remove |NaN| values.

allTimes = segmentTimesShifted(:);
allTemps = segmentTempsShifted(:);
allTimes(isnan(allTemps)) = [];
allTemps(isnan(allTemps)) = [];

%%
% Then I can fit a line to the data.
linfit = polyfit(allTemps,allTimes,1);

%%
% Let's see how well we fit the data.

hold on
h2 = plot(xlim,polyval(linfit,xlim),'r-');
linfitstr = sprintf('Linear Fit (y = %.1f*x + %.1f)',linfit(1),linfit(2));
legend([ h1(1), h2(1) ],{'Data',linfitstr},'Location','NorthWest')

%%
% _Figure 18: The time it takes to heat the living room along with a linear fit to the data._
%
% Not a bad fit. Looking closer at the coefficients from the linear fit, it
% looks like it takes about 3 minutes after the radiators start to heat up
% for the room to start to warm up. After that, it takes about 5 minutes
% for each degree of temperature increase.

%% What room takes the longest to warm up?
% I can apply the techniques above to each room to find out how long each
% room takes to warm up. I took the code above and put it into a separate
% function called <../temperatureAnalysis.m |temperatureAnalysis|>, and
% applied that to each inside temperature sensor.

inside = [1 5 9 12];

figure
xl = [0 14];
for s = 1:size(inside,2)
    linfits(s,1:2) = temperatureAnalysis(tempF(:,inside(s)), heaton, heatoff);
    y = polyval(linfits(s,1:2),xl) + heatondelay;
    plot(xl, y, lineSpecs{inside(s),1}, 'Color',lineSpecs{inside(s),2},...
        'DisplayName',location{inside(s)})
    hold on
end
legend('Location','NorthWest')
xlabel('Desired temperature increase (\circF)')
ylabel('Estimated minutes to heat')
title('Estimated Time to Heat Each Room')

%%
% _Figure 19: The estimated time it takes to heat each room in my apartment._

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]王晓银.基于XBee的瓦斯无线传感器网络节点的设计[J].自动化技术与应用,2018,37(08):46-49.

[2]王晓银.基于XBee的瓦斯无线传感器网络节点的设计[J].自动化技术与应用,2018,37(08):46-49.

🌈4 Matlab代码及数据

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/690130.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【MOOC 测验】第3章 运输层

1​、在 ISO/OSI 参考模型中&#xff0c;对于运输层描述正确的有&#xff08; &#xff09; A. 为传输数据选择数据链路层所提供的最合适的服务B. 为系统之间提供面向连接的数据传输服务C. 可以提供端到端的差错恢复和流量控制&#xff0c;实现可靠的数据传输D. 提供路由选择…

TP composer 新创建一个vendor2,作为新库下载目录

站点目录新建一个vendor2文件夹&#xff1a; 在里面新建一个 composer.json 文件&#xff1a;(只写一个花括号就行) {} 然后这个vendor2目录里&#xff0c;使用宝塔终端执行&#xff1a; composer require zoujingli/ip2region 这样&#xff0c;vendor2目录里就会再多出 v…

AI大模型应用时代,如何通过数据“造好品,卖好品”?

在数字化时代的浪潮中&#xff0c;品牌营销正面临着前所未有的挑战和机遇。随着技术的迅猛发展&#xff0c;消费者的行为和期望也在不断演变。 新的市场环境下&#xff0c;消费者的需求和购买行为发生了哪些变化&#xff1f; 数码家电转战社媒平台&#xff0c;竞争白热化如…

HAL库记录--外部中断

1.STM32CubaMX配置 2.分析生成代码 /*Configure GPIO pin : PtPin */GPIO_InitStruct.Pin GPIO_PIN_12;GPIO_InitStruct.Mode GPIO_MODE_IT_FALLING;GPIO_InitStruct.Pull GPIO_PULLUP;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);/* EXTI interrupt init*/HAL_NVIC_SetPri…

leetcode:191. 位1的个数(python3解法)

难度&#xff1a;简单 编写一个函数&#xff0c;输入是一个无符号整数&#xff08;以二进制串的形式&#xff09;&#xff0c;返回其二进制表达式中数字位数为 1 的个数&#xff08;也被称为汉明重量&#xff09;。 提示&#xff1a; 请注意&#xff0c;在某些语言&#xff08;…

经纬恒润OTA仿真测试解决方案为汽车智能化发展保驾护航

OTA技术是汽车实现完整网联化、智能化体验的基础&#xff0c;自被引用汽车以来&#xff0c;广受研发人员、市场用户的关注。近来&#xff0c;国家有关部门也陆续出台了相应政策&#xff0c;对汽车企业OTA技术的应用进行了约束和规范。因此&#xff0c;OTA技术在量产车型的应用落…

el-date-picker 前者选择日期 后者禁用 (包括时分)

<template><el-form><el-form-item prop"pullinDateTime" label"进站时间"><el-date-picker v-model"form.pullinDateTime" type"datetime" value-format"yyyy-MM-dd HH:mm:ss"placeholder"选择日…

【无标题】看IT小白花15分钟安装TitanIDE

作为大学刚毕业没多久的IT小白&#xff0c;入职了行云创新&#xff08;www.cloudtogo.cn&#xff09;的市场部&#xff0c;我的老大让我学习并熟悉公司的产品——TitanIDE&#xff0c;不只是局限于它的文字叙述&#xff0c;最好是能够动手实操一下&#xff0c;学会安装和使用的…

11--Gradle进阶 - Gradle任务的定义方式、指定任务的属性

11--Gradle进阶 - Gradle任务的定义方式、指定任务的属性 前言 在前面的篇章中&#xff0c;我们写了不少 task 任务&#xff0c;但是任务完整的定义方式&#xff0c;指定哪些任务属性 没有一个归纳的总结。 本篇章我们来熟悉一下。 任务定义方式 任务定义方式&#xff0c;总体分…

【机器学习】【期末复习】有关机器学习的计算题可供期末复习参考(带本人手写解答与思考)

本文为学校课程《机器学习》的期末复习材料&#xff0c;主要是关于一些机器学习模型的计算题的解答过程。 题目 构造平衡 KD 树ID3 与 C4.5 算法构建决策树模型朴素贝叶斯SVM求最大间隔分离超平面和分类决策函数EM算法K-means聚类adaboost计算概率图模型反向传播 构造平衡 KD 树…

学习adaboost(四,最后一次迭代,c#实现)

犯错3的3个弱分类就剩一个了&#xff0c;即x<8.5,标签1&#xff0c;else&#xff0c;标签-1。如果还搞不定&#xff0c;就得启用犯错4的分类器了&#xff0c;我们这一次是第三次迭代&#xff0c;和第二次没差别&#xff0c;我们看一下数据更新情况&#xff0c;希望是最后一次…

【Rust日报】2023-06-26 Rust 编写的 ChatGPT桌面应用

Rust 编写的 ChatGPT桌面应用 这是一个非官方的免费 ChatGPT 桌面应用, Rust 编写. 支持 Windows, Mac 和 Linux. 目前 38.3k ⭐️. github地址: https://github.com/lencx/ChatGPT 使用 github action 发布多平台的 rust 二进制程序 这篇文章是关于如何使用 GitHub Actions 进…

深蓝学院C++基础与深度解析笔记 第 7 章 深入 IO

1. IOStream 概述&#xff08;I&#xff1a;输入&#xff0c;O&#xff1a;输出&#xff09; ●IOStream 采用流式 I/O 而非记录 I/O (类似于数据库)&#xff0c;但可以在此基础上引入结构信息 ● 所处理的两个主要问题&#xff1a; – 表示形式的变化&#xff1a;使用格式化…

机器学习笔记 - 基于TensorRT或CUDA推理第一次速度慢的解决方案参考

一、简述 不管是基于CUDA还是基于TensorRT进行模型推理,都是分三个阶段,将数据从内存拷贝到显存,进行推理,将推理结果从显存拷贝到内存。 关于TensorRT推理,可以参考之前的博客。 机器学习笔记 - windows基于TensorRT的UNet推理部署_坐望云起的博客-CSDN博客NVIDIA Tenso…

linux sshd 病毒清理

原因&#xff1a;开启了flink web submit 具体原因不清楚&#xff0c;三个flink集群&#xff0c;只要开了这个就中毒 参考&#xff1a;解决linux中挖矿病毒 Linux系统常见的病毒介绍&#xff08;附解决方案&#xff09; 1、清理定时任务 修改cron 文件时 可能会存在被锁不允…

Cartographer自定义lua参数的方法

Cartographer中, 配置参数大多数都是从lua文件中得到的, 不是像其他的开源框架大多使用xml等文件进行参数配置. 假如我们要配置一个名字是rotation_condition的配置参数在pose_graph_2d.cc中, 想要使用方法为 options_.translation_condition()配置步骤如下: 1. 修改proto文件…

界面控件Telerik UI for WPF R2 2023——拥有全新的Windows 11精简主题

Telerik UI for WPF拥有超过100个控件来创建美观、高性能的桌面应用程序&#xff0c;同时还能快速构建企业级办公WPF应用程序。Telerik UI for WPF支持MVVM、触摸等&#xff0c;创建的应用程序可靠且结构良好&#xff0c;非常容易维护&#xff0c;其直观的API将无缝地集成Visua…

无线视频传输|介绍四款基于wifi模块的视频传输方案

为满足产品物联网升级过程中对更高分辨率的视频源的需求&#xff0c;本篇带大家一起来了解一下支持高清视频传输&#xff0c;能够有效解决现有无线视频传输方案中&#xff0c;传输距离短、延迟大、不稳定等问题的四款视频传输方案&#xff1a;无人机视频传输方案&#xff0c;20…

java.sql.Time 字段时区问题 Mybatis 源码分析

java.sql.Time 字段时区问题 系列文章目录 第一章 初步分析 第二章 Mybatis 源码分析 第三章 Jackson 源码分析 意想不到的Time处理类 文章目录 java.sql.Time 字段时区问题 系列文章目录前言Mybatis源码阅读1. ResultSetImpl部分源码&#xff1a;2. SqlTimeValueFactory部分…

git分支的更新按钮不可用,idea 的git命令无法识别

现象 从git分支签出其本地分支&#xff0c;但是签出之后该分支的更新按钮为灰色&#xff0c;我只能拉取&#xff0c;不能更新&#xff0c;也不能推送 解决 打开idea的终端&#xff0c;执行命令git branch --set-upstream-toorigin/远程上的分支名 。又引出另外一个问题无法识别…