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

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

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


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


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


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


目录


💥1 概述


📚2 运行结果


🎉3 参考文献


🌈4 Matlab代码及数据


💥1 概述

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


📚2 运行结果


26f7b3e515494248bc769bd82e98a10d.png

88ebe6211fff49689101843141ef23b7.png

5c370cf8f02741208bbc7dfe59a29fbd.png

f69bddf4d7ae4fa7ba39aed5dd5b15f3.png

eaf4e9c9b42a4865a9726dbe13f3308b.png

988b558ca32748bdb02c8b3dfabc547e.png

d2674b4bb67c487b9a0b17e3b6053e8a.png

425d8dc1109f455f99d6095336685b30.png

d60b4fa69c15463e978b6350016d6808.png

82d65a8ff4a4442c90300e33f93a625e.png

73637fe971824e1f98e40a704da724e2.png

b770623a25a84d3fa763817bfef6820f.png

82441bf731a04d958bdca0648f6ce60c.png

32f785c5b26647ab8593e74f656bafd7.png

8eb4f6d5373d4ee19417271c5338bd1f.png

e47bdba160ea4cbba20a23c764afc816.png

501ef5e98a4e4bfabd3d233684f95236.png

f5765c4738634899953188a8a9e7d196.png

2631ed21aa334c5a9e421f6797371f0f.png


部分代码:

%% 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代码及数据


相关文章
|
29天前
|
机器学习/深度学习 算法
基于改进遗传优化的BP神经网络金融序列预测算法matlab仿真
本项目基于改进遗传优化的BP神经网络进行金融序列预测,使用MATLAB2022A实现。通过对比BP神经网络、遗传优化BP神经网络及改进遗传优化BP神经网络,展示了三者的误差和预测曲线差异。核心程序结合遗传算法(GA)与BP神经网络,利用GA优化BP网络的初始权重和阈值,提高预测精度。GA通过选择、交叉、变异操作迭代优化,防止局部收敛,增强模型对金融市场复杂性和不确定性的适应能力。
169 80
|
17天前
|
机器学习/深度学习 数据采集 算法
基于GA遗传优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目基于MATLAB2022a实现时间序列预测,采用CNN-GRU-SAM网络结构。卷积层提取局部特征,GRU层处理长期依赖,自注意力机制捕捉全局特征。完整代码含中文注释和操作视频,运行效果无水印展示。算法通过数据归一化、种群初始化、适应度计算、个体更新等步骤优化网络参数,最终输出预测结果。适用于金融市场、气象预报等领域。
基于GA遗传优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
|
13天前
|
机器学习/深度学习 算法 计算机视觉
基于CNN卷积神经网络的金融数据预测matlab仿真,对比BP,RBF,LSTM
本项目基于MATLAB2022A,利用CNN卷积神经网络对金融数据进行预测,并与BP、RBF和LSTM网络对比。核心程序通过处理历史价格数据,训练并测试各模型,展示预测结果及误差分析。CNN通过卷积层捕捉局部特征,BP网络学习非线性映射,RBF网络进行局部逼近,LSTM解决长序列预测中的梯度问题。实验结果表明各模型在金融数据预测中的表现差异。
|
23天前
|
机器学习/深度学习 算法
基于遗传优化的双BP神经网络金融序列预测算法matlab仿真
本项目基于遗传优化的双BP神经网络实现金融序列预测,使用MATLAB2022A进行仿真。算法通过两个初始学习率不同的BP神经网络(e1, e2)协同工作,结合遗传算法优化,提高预测精度。实验展示了三个算法的误差对比结果,验证了该方法的有效性。
|
25天前
|
机器学习/深度学习 数据采集 算法
基于PSO粒子群优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目展示了基于PSO优化的CNN-GRU-SAM网络在时间序列预测中的应用。算法通过卷积层、GRU层、自注意力机制层提取特征,结合粒子群优化提升预测准确性。完整程序运行效果无水印,提供Matlab2022a版本代码,含详细中文注释和操作视频。适用于金融市场、气象预报等领域,有效处理非线性数据,提高预测稳定性和效率。
|
2月前
|
监控 安全
公司上网监控:Mercury 在网络监控高级逻辑编程中的应用
在数字化办公环境中,公司对员工上网行为的监控至关重要。Mercury 作为一种强大的编程工具,展示了在公司上网监控领域的独特优势。本文介绍了使用 Mercury 实现网络连接监听、数据解析和日志记录的功能,帮助公司确保信息安全和工作效率。
113 51
|
1月前
|
运维 监控 安全
公司监控软件:SAS 数据分析引擎驱动网络异常精准检测
在数字化商业环境中,企业网络系统面临复杂威胁。SAS 数据分析引擎凭借高效处理能力,成为网络异常检测的关键技术。通过统计分析、时间序列分析等方法,SAS 帮助企业及时发现并处理异常流量,确保网络安全和业务连续性。
58 11
|
2月前
|
机器学习/深度学习 算法 Serverless
基于WOA-SVM的乳腺癌数据分类识别算法matlab仿真,对比BP神经网络和SVM
本项目利用鲸鱼优化算法(WOA)优化支持向量机(SVM)参数,针对乳腺癌早期诊断问题,通过MATLAB 2022a实现。核心代码包括参数初始化、目标函数计算、位置更新等步骤,并附有详细中文注释及操作视频。实验结果显示,WOA-SVM在提高分类精度和泛化能力方面表现出色,为乳腺癌的早期诊断提供了有效的技术支持。
|
1月前
|
机器学习/深度学习 算法 信息无障碍
基于GoogleNet深度学习网络的手语识别算法matlab仿真
本项目展示了基于GoogleNet的深度学习手语识别算法,使用Matlab2022a实现。通过卷积神经网络(CNN)识别手语手势,如&quot;How are you&quot;、&quot;I am fine&quot;、&quot;I love you&quot;等。核心在于Inception模块,通过多尺度处理和1x1卷积减少计算量,提高效率。项目附带完整代码及操作视频。
|
20天前
|
传感器 算法
基于GA遗传优化的WSN网络最优节点部署算法matlab仿真
本项目基于遗传算法(GA)优化无线传感器网络(WSN)的节点部署,旨在通过最少的节点数量实现最大覆盖。使用MATLAB2022A进行仿真,展示了不同初始节点数量(15、25、40)下的优化结果。核心程序实现了最佳解获取、节点部署绘制及适应度变化曲线展示。遗传算法通过初始化、选择、交叉和变异步骤,逐步优化节点位置配置,最终达到最优覆盖率。

热门文章

最新文章