function emda(fileuse)
%EMDA(fileuse): Analyzes data with the EMD Transform
%
%  fileuse ('choosenew'): whether to choose a new file set or use an old one
%
%Examples:
%  emdv
%  emdv('useold');

if (nargin==0)
  fileuse = 'choosenew';
end %if

[ecgfilename, cdfilename, rrfilename, hrfilename, ecgfilenameonly] = chooser(fileuse);
[hrt hr] = textread(hrfilename,'%f %f',-1, 'headerlines', 1);
[imf] = emd(hr,hrt);
emd_visu(hr,hrt,imf);
[iha ihf] = hhspectrum(imf);
[im hrtp] = toimage(iha,ihf,hrt(2:(length(hrt)-1)));
disp_hhs(im,hrtp);
figure;
fs = textread(hrfilename,'%f',1);
gfs = sum(im,2);
plot([length(gfs):-1:1]/length(gfs)*fs/2,gfs);
xlabel(['Frequency (Hz)'])
ylabel(['Sqrt(Power)'])
title('Hilbert-Huang Marginal Spectrum')