function [phi,psi] = mnf2(X)
% function [psi,phi] = mnf(X)
%    X - an p x N data matrix  (N is number of samples)
%
% Out:
%    psi - the mixing coefficients (pxp)
%   phi - basis  p x N
%
% Example:
%    s = sin(0:99);
%    n = [zeros(1,50) rand(1,50)];
%    M = [1 0.5; 0.2 0.8];
%    X = M * [s;n];
%    subplot(2,1,1);
%    plot(X');
%    subplot(2,1,2);
%    [psi,phi] = mnf2(X);
%    plot(phi');


[p,N] = size(X);

dX = X(:,1:end-1) - X(:,2:end);

[psi,D] = eig(X*X', dX*dX');

phi = psi' * X;
psi = psi'; % to agree with output of mnf.m
