% demo_ampDemodulate - script to demonstrate AM demodulator
%
% Usage:
%   demo_ampDemodulate
%
% See also:
%   ampDemodulate, demo_ampModulate
%
% This script assumes that demo_ampModulate was run, so that the two
% passband signals sp and sps (and related) exist in the workspace.

%% Demo 1: a few cycles of a sinusoid
ssd = ampDemodulate(sp, fc, BW, false, fs);

% plot demodulated signal and original signal
ttd = (0:length(ssd)-1)/fs;

figure(1)
plot(ttm, ss, 'b', ttd, ssd, 'r');
grid on
xlabel('Time (s)');
ylabel('Amplitude');
legend('Message Signal', 'Demodulated Signal', 'Location', 'SouthEast');

%% Demo 2: recover speeach signal
sssd = ampDemodulate(sps, fcs, BWs, false, fss);

% plot a few samples of original and demodulate signal
tts = (0:length(sss)-1)/fss;
ttsd = (0:length(sssd)-1)/fss;

figure(2);
% we delay the demodulated signal to account for the filter delays; each
% filter induces a delay of 25 samples.
plot(ttsd(1000:2000), 2*sssd(1050:2050), 'r', ...
    tts(1000:2000), sss(1000:2000), 'b')
grid on
xlabel('Time (s)');
ylabel('Amplitude');
legend('Demodulated Signal', 'Message Signal', 'Location', 'SouthEast');
