function emd_visu(x,t,imf,i);

% EMD_VISU(x,t,imf,i) displays the ouput of "emd"
%
% inputs: - x : analyzed signal
%         - t : time instants
%         - imf : intrinsic mode functions, output of emd.m
%         - i (optional): figure number

mx = min(x);
Mx = max(x);

s = size(imf);
k = s(1);

M = max(max(abs(imf(1:k-1,:))));

if(nargin==4)
  figure(i)
else
  figure
end

subplot(k+1,1,1)
plot(t,x)
axis([t(1) t(s(2)) mx Mx])
set(gca,'YTick',[])
set(gca,'XTick',[])
ylabel(['signal'])

for j = 1:k-1
        subplot(k+1,1,j+1)
        plot(t,imf(j,:))
        axis([t(1) t(s(2)) -M M])
        set(gca,'YTick',[])
        set(gca,'XTick',[])
        ylabel(['imf',int2str(j)])
end
subplot(k+1,1,1)
title('Empirical Mode Decomposition')

subplot(k+1,1,k+1)
plot(t,imf(k,:),'r')
mr = min(imf(k,:));
Mr = max(imf(k,:));
axis([t(1) t(s(2)) mr Mr])
ylabel('res.')
