Main Content

Remove High-Frequency Noise from Gyroscope Data

This example shows how to remove the high-frequency outliers from a streaming signal using the dsp.MedianFilter System object?.

Use the dsp.MatFileReader System 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 the X-axis, Y-axis, and Z-axis data from the gyroscope motion sensor. Choose a frame size of 714 samples so that each column of the data contains 10 frames. The dsp.MedianFilter System object uses a window length of 10. Create a timescope object 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 the dsp.MedianFilter System object. View the filtered Z-axis data in the time scope.

for i = 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