www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ComputeTheMovingRMSOfANoisyRampSignalExample.m
%% Moving RMS of Noisy Square Wave Signal % Compute the moving RMS of a noisy square wave signal with varying % amplitude using the |dsp.MovingRMS| object. %% Initialization % Set up |movrmsWin| and |movrmsExp| objects. |movrmsWin| % uses the sliding window method with a window length of 20. |movrmsExp| % uses the exponential weighting method with a forgetting factor % of 0.995. Create a time scope for viewing the output. FrameLength = 10; Fs = 100; movrmsWin = dsp.MovingRMS(20); movrmsExp = dsp.MovingRMS('Method','Exponential weighting',... 'ForgettingFactor',0.995); scope = dsp.TimeScope('SampleRate',Fs,... 'TimeSpanOverrunAction','Scroll',... 'TimeSpan',100,... 'ShowGrid',true,... 'YLimits',[-1.0 5.5]); title = 'Sliding Window RMS (blue) and Exponentially Weighted RMS (red)'; scope.Title = title; %% Compute the RMS % Generate a noisy square wave signal. Vary the amplitude of the square % wave after a given number of frames. Apply the sliding window method and % the exponential weighting method on this signal. View the output on the % time scope. count = 1; Vect = [1/8 1/2 1 2 3 4]; index = 1; for index = 1:length(Vect) V = Vect(index); for i = 1:160 x = V + 0.1 * randn(FrameLength,1); y1 = movrmsWin(x); y2 = movrmsExp(x); scope([x,y1,y2]); end end