%----------------------------------------------------------------------
% Physiology 317 - Methods in Computational Neurobiology
%
% hw0p1.m - Homework #0, Problem #1
%
% Generate and plot an amplitude-modulated sine wave
%
% M. Nelson  2000
%----------------------------------------------------------------------

clear;					% clear variables
clf reset;				% clear figure
orient tall; 				% full page (portrait)

%
% Initialization
%
DT = 0.02;				% time step
TMAX = 10.0;				% max time
carrierFreq = 2.0;			% carrier frequency (Hz)
modFreq = 0.5;				% modulation frequency (Hz)

%
% Construct the time and signal vectors
%
t=0:DT:TMAX;				% time vector
carrier = sin(2*pi*carrierFreq*t);	% carrier signal
mod = 1.0 - 0.5*cos(2*pi*modFreq*t);	% modulation signal
signal = mod .* carrier;		% amplitude-modulated signal

%
% Plot the carrier signal
%
subplot(3,1,1);
plot(t,carrier,'b-');
title('AMPLITUDE-MODULATED SINE WAVE,  M. Nelson  19 Jan 00');
ylabel('carrier');
axis([0 10 -2 2]);
grid on;

%
% Plot the modulation signal
%
subplot(3,1,2);
plot(t,mod,'r--');
ylabel('mod');
axis([0 10 0 2]);
grid on;

%
% Plot the amplitude-modulated signal
%
subplot(3,1,3);
plot(t,signal); hold on;
plot(t,mod,'r--');
plot(t,-mod,'r--');
xlabel('time (s)');
ylabel('carrier * mod');
axis([0 10 -2 2])
grid on;
