Remove High-Frequency Noise in Measured Data

This example shows how to design a low-pass filter and use it to remove high-frequency noise in measured data. High-frequency noise is due to components of a signal varying faster than the signal of interest. Removing high-frequency noise allows the signal of interest to be more compactly represented and enables more accurate analysis. A low-pass filter is a common techqnique for removing high-frequency noise in a signal.

Read Data

The ThingSpeak™ channel 12397 contains data from the MathWorks® weather station, located in Natick, Massachusetts. The data is collected and posted to ThingSpeak once per minute. Field 3 of the channel contains relative humidity data. Read the data using the thingSpeakRead function.

[humidity,time] = thingSpeakRead(12397,'NumPoints',8000,'Fields',3);

Design Filter

A filter is a process that removes unwanted components from a signal. A low-pass filter is designed to let lower frequency components pass through and block higher frequency components in a signal. DSP System Toolbox™ provides multiple techniques to define a low-pass filter. This example designs a third-order finite impulse response (FIR) filter. The sampling frequency is once every 60 seconds (Fs=1/60), as the data in channel 12397 is uploaded once per minute. The low-pass filter keeps low frequency components and attenuates high-frequency components with a period of less than 24 hours.

filtertype = 'FIR';
Fs = 1/60;
N = 3;
Fpass = 1/(24*60*60);
Fstop = 1/(2*60*60);
Rp = 0.5;
Astop = 50;

LPF = dsp.LowpassFilter('SampleRate',Fs,...

Process and Send the Data to ThingSpeak

Process the relative humidity data using the low-pass filter, and send the filtered humidity data to a ThingSpeak channel using the thingSpeakWrite function.

Output = step(LPF, humidity);

Using the MATLAB Analysis app, you can write the data to a channel. If you are using the MATLAB Visualizations app, you can also add a plot of the data. Change the channelID and the writeAPIKey to send data to your channel.

channelID = 17504;
ylabel('Relative Humidity');
legend('Raw Data', 'Filtered Data');

The plot demonstrates a dramatic reduction in high-frequency noise.

See Also


Related Topics