www.gusucode.com > coder_compiler_dsp 案例源码程序 matlab代码 > coder_compiler_dsp/myRLSFilterSystemIDApp.m
function scopeHandles = myRLSFilterSystemIDApp(numTSteps) % myRLSFilterSystemIDApp initialize and execute RLS Filter % system identification example. Then, display results using % scopes. The function returns the handles to the scope and UI objects. % % Input: % numTSteps - number of time steps % Outputs: % scopeHandles - Handle to the visualization scopes . % Copyright 2013-2016 The MathWorks, Inc. if nargin == 0 numTSteps = Inf; % Run until user stops simulation. end % Create scopes tfescope = dsp.ArrayPlot('PlotType','Line',... 'Position',[8 696 520 420],... 'YLimits',[-80 30],... 'SampleIncrement',1e4/1024,... 'YLabel','Amplitude (dB)',... 'XLabel','Frequency (Hz)',... 'Title','Desired and Estimated Transfer Functions',... 'ShowLegend',true,... 'XOffset',-5000); msescope = dsp.TimeScope('SampleRate',1e4,'TimeSpan',.01,... 'Position',[8 184 520 420],... 'YLimits',[-300 10],'ShowGrid',true,... 'YLabel','Mean-Square Error (dB)',... 'Title','RLSFilter Learning Curve'); screen = get(0,'ScreenSize'); outerSize = min((screen(4)-40)/2, 512); tfescope.Position = [8, screen(4)-outerSize+8, outerSize+8,... outerSize-92]; msescope.Position = [8, screen(4)-2*outerSize+8, outerSize+8, ... outerSize-92]; % Create UI to tune FIR filter cutoff frequency and RLS filter % forgetting factor Fs = 1e4; param = struct([]); param(1).Name = 'Cutoff Frequency (Hz)'; param(1).InitialValue = 0.48 * Fs/2; param(1).Limits = Fs/2 * [1e-5, .9999]; param(2).Name = 'RLS Forgetting Factor'; param(2).InitialValue = 0.99; param(2).Limits = [.3, 1]; hUI = HelperCreateParamTuningUI(param, 'RLS FIR Demo'); set(hUI,'Position',[outerSize+32, screen(4)-2*outerSize+8, ... outerSize+8, outerSize-92]); clear HelperUnpackUDP % Execute algorithm while(numTSteps>=0) drawnow limitrate; % needed to process UI callbacks [tfe,err,pauseSim,stopSim] = myRLSFilterSystemIDSim(); if stopSim % If "Stop Simulation" button is pressed break; end if pauseSim continue; end % Plot transfer functions tfescope(20*log10(abs(tfe))); % Plot learning curve msescope(10*log10(sum(err.^2))); numTSteps = numTSteps - 1; end if ishghandle(hUI) % If parameter tuning UI is open, then close it. delete(hUI); drawnow; clear hUI end scopeHandles.tfescope = tfescope; scopeHandles.msescope = msescope; end