Main Content

Visualize Peaks in Your Data

This example shows how to visualize the peaks (local maxima) in your data in ThingSpeak™ channel.

Read Car Counter Data from ThingSpeak Channel

The car-counter ThingSpeak channel uses a Raspberry Pi™, and a webcam to count cars on a busy highway. A car-counting algorithm is running on the Raspberry Pi, and the number of cars counted every 15 seconds is sent to ThingSpeak. Use the thingSpeakRead function to read the last 120 data points for eastbound traffic from channel 38629.

data = thingSpeakRead(38629,'NumPoints',120,'Fields',2,'outputFormat','table');

Find Peaks

The highway often backs up due to rush hour traffic or traffic incidents. Traffic backup is indicated on the highway by peaks in the number of cars counted every 15 seconds. Visualize the instances at which the density was more than 15 over the last 120 data points.

findpeaks(data.DensityOfEastboundCars,data.Timestamps,'MinPeakHeight',15);
title('Eastbound Peaks');

The plot shows instances in the last 120 minutes when there were more than 15 cars crossing the east bound highway in a 15-second window.

Since the data is based on real traffic, it is possible that there are no peaks over the value specified in the findpeaks function. If your function does not return any peaks, experiment with the MinPeakHeight (15) or the number of data points read from ThingSpeak (120).

See Also

Functions