数据峰值分析
此示例显示如何对 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