clear all;
srate = 44100;
dur = 1000;
fc = 400;			% carrier frequency
f=40;

mrate_fm = 4;		% modulation rate
mindex_fm = 100;	% modulation index (for fm = max_freq_change/modulation rate)
amp_fm = 0.5;

mrate_am = 39;		%modulation rate
mindex_am = 1;		%modulation index (for FM = proportional change in amplitude - 1 = 100%)
amp_am = 0.25;		%base amplitude carrier !!! watch for clipping with modualtion

wdms = 10;			% window to stop click(need wind.m in same directory)
t = [ 0 : 1/srate : dur/1000 ];
% end of user input


y_fm  = amp_fm * sin((2 * pi * fc * t) + (-mindex_fm * sin(2 * mrate_fm * pi * t))) ;
y_fm = wind(srate,wdms,y_fm);
wavwrite(y_fm, srate, ['fm_tone']);
%sound(y_fm,srate)


y_am  = (1 + (mindex_am * sin(2* mrate_am * pi * t)))  .* (amp_am * sin(2 * pi* fc * t)) ;
y_am = wind(srate,wdms,y_am);
wavwrite(y_am, srate, ['am_tone']);
%sound(y_am,srate)

y1 = y_am + y_fm;
wavwrite(y1,srate, ['am_fm_tone']);
y2=y_am - y_fm;
%  	e1_fs2_filt = abs(zfilt1) .* cos(angle(zfilt2));

y3 = 0.5*sin(2*pi*f*t);
y3 = wind(srate,wdms,y3);
y4= abs(y3) .* cos(angle(y_fm));

subplot(4,1,1);
plot(t,y_fm);
axis([0 0.1 -0.5 0.5]);
subplot(4,1,2);
plot(t,y_am);
axis([0 0.1 -0.5 0.5]);
subplot(4,1,3);
plot(t,y3);
axis([0 0.1 -0.5 0.5]);
subplot(4,1,4);
plot(t,y4);
axis([0 0.1 -0.6 0.6]);
% subplot(4,2,1);
% plot(t,y1);
% axis([0 0.1 -0.5 0.5]);
% subplot(4,2,2);
% plot(t,y2);
% axis([0 0.1 -0.5 0.5]);