数据峰值分析
此示例展示了如何对 ThingSpeak™通道中的数据执行基本峰值分析。您将学习如何计算数据中的峰值。
从汽车计数器 ThingSpeak 通道读取数据
汽车计数器 ThingSpeak通道使用 Raspberry Pi™ 和网络摄像头对繁忙高速公路上的汽车进行计数。Raspberry Pi 上运行汽车计数算法,每 15 秒计数的汽车密度会发送到 ThingSpeak。使用 thingSpeakRead
函数读取来自通道38629 的东向流量的最后 60 个数据点。
data = thingSpeakRead(38629,'NumPoints',60,'Fields',1,'outputFormat','table');
寻找峰值
由于高峰时段交通或交通事故,高速公路经常出现拥堵。因此,高速公路上的交通拥堵是通过每 15 秒统计一次的汽车密度峰值来表示的。驾驶员的一般规则是遵守前方车辆的三秒规则。计算过去 60 个数据点中汽车密度每秒超过 15 辆的次数。
[peakValues, peakLocations] = findpeaks(data.DensityOfWestboundCars,data.Timestamps,'MinPeakHeight',10);
numOccurences = length(peakValues);
disp(numOccurences);
11
将峰值出现次数发送至 ThingSpeak
使用 thingSpeakWrite
函数将 numOccurences
值发送到 ThingSpeak通道。更改 channelID
和 writeAPIKey
以将数据发送到您的通道。
channelID=17504; writeAPIKey='23ZLGOBBU9TWHG2H'; thingSpeakWrite(channelID,numOccurences,'WriteKey',writeAPIKey);
另请参阅
函数
thingSpeakWrite
|findpeaks
(Signal Processing Toolbox) |thingSpeakRead