% % For illustrative purposes this duplicates the MATLAB code on % pig 73 from the book but specified for the problem 4.3.2 on epage % % 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 = 512; n = 0:(N-1); % our desired signal d(n): % dn = (0.99.^n) .* sin( 0.1*n*pi + 0.2*pi ); %dn = sin( 0.01*n*pi + 0.2*pi ); % the random driving input noise ... used in creating the observed noises v_1(n) and v_2(n) % v = randn(1,N); % the coefficients of the ARMA(1,1) models for v_1(n) and v_2(n) % a1 = 0.8; a2 = -0.95; % plot the pure signal d(n) with the noised signal d(n) + v_1(n) % fo=figure; hd=plot( n, dn, '-og', 'markersize', 6 ); hold on; % <- the pure signal d(n) % get the noised signal to plot i.e. xn % [yw,w,en,xn] = aawienernoisecancelor(dn,a1,a2,v,2,N); hdn=plot( n, xn, '-xr' ); xlabel( 'n' ); ylabel( 'measured signal' ); title( 'the pure signal and the signal with noise' ); %axis( [0,256,-Inf,+Inf] ); axis( [0,256,-4.5,+4.5] ); legend( [hd,hdn], { 'd(n)', 'd(n)+v_1(n)' }, 'location', 'north' ); saveas( gcf, '../../WriteUp/Graphics/Chapter4/noise_cancelor_fig_1.eps', 'epsc' ); % compare our signal approxmation for various filter lengths: % mArray = [ 4,8,16 ]; a_hands = []; clrs = 'brgkcm'; for mi=1:length(mArray), thisM = mArray(mi); [yw,w,en,xn] = aawienernoisecancelor(dn,a1,a2,v,mArray(mi),N); %a_hands = [ a_hands, plot(n,en,['-',clrs( mod(mi-1,length(clrs))-1 ) ] ); figure; plot( n, dn, '-og', 'markersize', 6 ); hold on; plot( n, en, '-xk' ); xlabel( 'n' ); ylabel( 'approximate signal' ); title( ['M=',num2str(thisM)] ); %axis( [0,256,-Inf,+Inf] ); axis( [0,256,-4.5,+4.5] ); saveas( gcf, ['../../WriteUp/Graphics/Chapter4/noise_cancelor_M_',num2str(thisM),'.eps'], 'epsc' ); end