% makes sinusoidal frequency modulation of tone carrier
srate = 44100;
dur = 1;

fc = 1000;       % carrier frequency

mrate = 4;      % modulation rate

mindex = 100;   % modulation index (for fm = max_freq_change/modulation rate = (fc +/- mindex)/mrate)

amp = 0.5;

wdms = 10;      % window to stop click(need wind.m in same directory)
% end of user input


t = [ 0 : 1/srate : dur-1/srate ];

y_fc = [2 * pi * fc * t];

y_fm = [-mindex * sin(2 * mrate * pi * t)];

y = amp * sin( y_fc + y_fm);

y = wind(srate,wdms,y);

wavwrite(y, srate, ['fm_tone.wav']);

sound(y,srate)

figure
plot(t,y);
axis([0 dur/2 -1 1]);