
% cricket call example for ECE4760
figure(1); clf;
clear all; 

Fs = 44100 ;
t = 0:1/Fs:2 ;
t_samp = 0:length(t)-1 ;

song = zeros(size(t));
envelope = zeros(size(t));

chirp_rep = 0.5 ; % chirp repeat interval
syl_dur = 0.02 ; % sylable duration
syl_rep = 0.05 ; % sylable repeat interval
syl_num = 4 ; % sylable count
burst_freq = 2500 ;  % carrier frequency

chirp_rep = fix(chirp_rep*Fs) ; % chirp repeat interval in sample units
syl_dur = fix(syl_dur*Fs) ; % sylable duration in sample units
syl_rep = fix(syl_rep*Fs) ; % sylable repeat interval in sample units

% build the on-off waveform
chirp_start = mod(t_samp, chirp_rep)==0 ;
chirp_start_index = find(chirp_start == 1);
for i = chirp_start_index
	for j = 0:syl_num-1
		envelope(i+j*syl_rep:i+j*syl_rep+syl_dur) = 1;
	end
end

% make the linear rise and fall of each sylable
conv_mask = ones(1,fix(0.004*Fs));
envelope = conv(envelope, conv_mask);

% modulate with the envelope
song = envelope(1:length(song)) .* sin(2*pi*burst_freq*t) ;

plot(t, song, 'r') ;

soundsc(song, 44100)







