% this code plots the matched filter output waveform 
% in problem 2.1
fs = 100;
tmin = -2;
tmax = 2;
t = tmin : 1/fs : tmax;
sigRe = ( t >= 1 ) & (t <= 2 );
sigIm = (t >= -1.5) & (t <= 0) ;
sigIm = sigIm.*( -t - 1.5);
sig = sigRe + 1i.*sigIm;
% plot the s(t) in the same graph
plot(t, sigRe, t , sigIm);

% matched filtering
sigMF = conj(sig(end: -1 : 1));
tomin = 2*tmin;
tomax = 2*tmax;
to = tomin : 1/fs : tomax;
% convolution
sigOut = conv(sig, sigMF)/fs;
% plot the output waveform
plot(to, real(sigOut), to, imag(sigOut), to, abs(sigOut) );
legend('real part of s*h', 'imaginary part of s*h', '|s*h|');
grid on;
