% plot_sampledChirp - illustrate folding and aliasing via chirp signal

%% Parameters
fs = 5000;  % 44.1KHz for oversampling, 8192 for undersampling
%fs = 44100;

% chirp: 0 to 20KHz in 10 seconds 
fstart   = 0;
fend     = 20e3;
dur      = 10;

%% generate signal
tt   = 0:1/fs:dur;
psi  = 2*pi*(fend-fstart)/(2*dur)*tt.^2;  % phase function
xx   = cos(psi);

%% spectrogram
spectrogram( xx, 256, 128, 256, fs,'yaxis');

%% play sound
soundsc( xx, fs);
%wavwrite( xx/max(abs(xx)), fs, 8, '../figures/sampledChirp.wav')

%% Store name of script for automated figure generation
ScriptName = mfilename;