% click demo
clear all
figure(1)
Fs=8000;
t=0:1/Fs:2.0;
wave = sin(2*pi*400*t);

% on/off modulation -- clicks badly
sq_mod = max(square(2*pi*15*t),0);
sound(wave .* sq_mod);
subplot(3,2,1)
plot(wave .* sq_mod)
set(gca, 'xlim', [1.54 1.59]*1e4)
subplot(3,2,2)
pwelch(wave .* sq_mod)
set(gca, 'xlim', [0 .2])

pause(1)

% sine modulation
sin_mod = max(sin(2*pi*15*t),0);
sound(wave .* sin_mod);
subplot(3,2,3)
plot(wave .* sin_mod)
set(gca, 'xlim', [1.54 1.59]*1e4)
subplot(3,2,4)
pwelch(wave .* sin_mod)
set(gca, 'xlim', [0 .2])

pause(1)
 
%ramp in about 5 mSec
ramp_mod = min(1, 2.5*max(sawtooth(2*pi*15*t, 0.5), 0));
sound(wave .* ramp_mod);
subplot(3,2,5)
plot(wave .* ramp_mod)
set(gca, 'xlim', [1.55 1.6]*1e4)
subplot(3,2,6)
pwelch(wave .* ramp_mod)
set(gca, 'xlim', [0 .2])