% Illustrate removing high-freq interference via low-pass

%% parameters
fs = 11025;
dur = 2;
tt = 0:1/fs:dur;

%% the signal of interest
xx = cos(2*pi*500*tt) .* (1+1*cos(2*pi*5*tt));
ff = [495 500 505];
XX = [0.5 0.5 0.5];

subplot(2, 1, 1 )
plot(tt, xx );
grid
xlabel( 'Time (s)' );

subplot( 2, 1, 2)
stem(ff,XX);
xlabel( 'Frequency (Hz)' )
axis( [ 400 1200 0 1] )
grid

soundsc( xx, fs );

pause

%% the corrupted signal
yy = xx + 10*cos(2*pi*fs/10*tt + pi/2 );
ff = [ff fs/10];
YY = [XX 5];
subplot( 2, 1, 1)
plot( tt, yy );
grid
xlabel( 'Time (s)' );

subplot( 2, 1 , 2 )
stem(ff,YY);

xlabel( 'Frequency (Hz)' )
axis( [ 400 1200 0 6] )
grid

soundsc( yy, fs );

pause

%% filter
bb = ones( 1, 10) / 10;

subplot( 1, 1, 1)
freqz(bb, 1, 512, fs);

pause

%% cleaned signal
zz = filter( bb, 1, yy);
plot( tt, zz );
grid
xlabel( 'Time (s)' );

soundsc( zz, fs );
