%
%   ECG
%

% Construct artificial max/min signal and constructs the
% continuous wavelet transform to show how one can
% extract minima, maxima, and inflection points

% uses CWT_Wavelab, ImageCWT (continuous wavelet transform, and its plot)
% 

% construction of the signal

	n = 1024;
	t = (1:n);
	A1 = 15; b1 = 1700; m1 = 150;
    A2 = 0.3; b2 = 2500; m2 = 525;
	ecgs = A1*exp(-(t-m1).^2/b1);
	ecgs = ecgs+A2*(t-m2).*exp(-(t-m2).^2/b2);
    A3 = 0.0001; m3 = 900;
	ecgs = ecgs + A3*(t-m3).^3.*exp(-(t-m3).^2/b2);

	t=t./n;

	%figure(1);
	subplot(311)
	plot(ecgs); title('test function','FontSize',16)
	axis([1 1024 -10 15]); 
	%print -deps /home/ade/SIGNALS/ecgtest.eps

% continuous wavelet trabsform

	cwt = CCWT(ecgs,96,'Sombrero');

% modulus

	cwtm = abs(cwt);
    cwtmax = max(max(cwtm)); cwtmin = min(min(cwtm));
	cwtm = 255*(cwtm-cwtmin)/(cwtmax-cwtmin);

	%figure(2);
	subplot(312),
	ImageCWT(cwtm,'Individual','gray'),
	title('Modulus of complex CWT','FontSize',16)
	%print -deps /home/ade/SIGNALS/mCWTecgtest.eps

% phase

	cwtphase = abs(angle(cwt)/pi);
    cwtphase = 255*cwtphase;
	cwtphase = 255-cwtphase;

	%figure(3);
	subplot(313),
	ImageCWT(cwtphase,'Individual','gray')
    title('Phase of complex CWT','FontSize',16)
	%print -deps /home/ade/SIGNALS/phCWTecgtest.eps
