Main Content

Remove High-Frequency Noise from Gyroscope Data

This example shows how to remove the high-frequency outliers from a streaming signal using thedsp.MedianFilterSystem object?.

Use thedsp.MatFileReaderSystem object to read the gyroscope MAT file. The gyroscope MAT file contains 3 columns of data, with each column containing 7140 samples. The three columns represent theX-axis,Y-axis, andZ-axis data from the gyroscope motion sensor. Choose a frame size of 714 samples so that each column of the data contains 10 frames. Thedsp.MedianFilterSystem object uses a window length of 10. Create atimescopeobject to view the filtered output.

reader = dsp.MatFileReader('SamplesPerFrame',714,...'Filename','LSM9DS1gyroData73.mat',...'VariableName','data'); medFilt = dsp.MedianFilter(10); scope = timescope('NumInputPorts',1,...'SampleRate',119,...'YLimits',[-300 300],...'ChannelNames',{'Input','Filtered Output'},...'TimeSpanSource','Property',...'TimeSpan',60,'ShowLegend',true);

Filter the gyroscope data using thedsp.MedianFilterSystem object. View the filteredZ-axis data in the time scope.

fori = 1:10 gyroData = reader(); filteredData = medFilt(gyroData); scope([gyroData(:,3),filteredData(:,3)]);end

The original data contains several outliers. Zoom in on the data to confirm that the median filter removes all the outliers.

Related Topics