% % For illustrative purposes this duplicates the MATLAB results on % epage 117 from the book. % % Written by: % -- % John L. Weatherwax 2008-11-24 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- addpath( '../../AdaptiveFilteringCode/' ); clear functions; clear; %clc; close all; drawnow; randn('seed',0); rand('seed',0); N = 2^10; n = 0:(N-1); plt_inds = 512:(2^(10)); % the random driving input noise ... used in creating the observed noises v_1(n) and v_2(n) % v = randn(1,N); % our input signal is given by x(n) ... % ... we want to predict this signal from the previous two values: % a_coefs = [ 1, -0.601, +0.7725, ]; b_coefs = [ 1 ]; x = filter( b_coefs, a_coefs, v ); % plot the input signal x(n) % fo=figure; hd=plot( n(plt_inds), x(plt_inds), '-og', 'markersize', 6 ); hold on; % <- the observed signal ... M = 2; % % for one learning rate: % mu = 0.02; [w,y,e,J,w1] = aalmsonesteppredictor(x,mu,M); figure(fo); plot( n(plt_inds), y(plt_inds), '-xr' ); % <- the predicted signal fe = figure; eh1 = plot( n, e, '-k' ); hold on; % <- the error as a function of n fw = figure; ws1 = plot( w1, '-' ); hold on; % <- the convergence of the weights ... % % for another learning rate: % mu = 0.005; [w,y,e,J,w1] = aalmsonesteppredictor(x,mu,M); figure(fo); plot( n(plt_inds), y(plt_inds), '-xk' ); axis tight; xlabel( 'n' ); ylabel( 'predictions' ); saveas( gcf, '../../WriteUp/Graphics/Chapter7/lin_pred_signal_plus_pred.eps', 'epsc' ); figure(fe); eh2 = plot( n, e, '-r' ); axis tight; xlabel( 'n' ); ylabel( 'prediction error' ); saveas( gcf, '../../WriteUp/Graphics/Chapter7/lin_pred_error.eps', 'epsc' ); figure(fw); ws2 = plot( (w1), '-' ); axis tight; plot( n, -a_coefs(2)*ones(1,N), '-g', 'LineWidth', 4 ); plot( n, -a_coefs(3)*ones(1,N), '-g', 'LineWidth', 4 ); %ledgend( [ ws1, ws2 ], {'','','',''} ); xlabel( 'n' ); ylabel( 'weight convergence' ); title( 'convergence of the weights' ); saveas( gcf, '../../WriteUp/Graphics/Chapter7/lin_pred_weight_conv.eps', 'epsc' );