www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/RemoveHighFrequencyNoiseFromGyroscopeDataExample.m

    %% 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(TM).

%%
% 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
% the data contains 10 frames. The |dsp.MedianFilter| System object uses a 
% window length of 10. Create a |dsp.TimeScope| object to view the filtered 
% output.
reader = dsp.MatFileReader('SamplesPerFrame',714,'Filename','LSM9DS1gyroData73.mat',...
    'VariableName','data');
medFilt = dsp.MedianFilter(10);
scope = dsp.TimeScope('NumInputPorts',1,'SampleRate',119,'YLimits',[-300 300],...
    'ChannelNames',{'Input','Filtered Output'},'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.
%
% <<../zoomedData.png>>
%