function [Dksvd,g,err]=testdemo
%testdemo K-SVD training demonstration.
%  
%  Tao Xu
%  CVSSP
%
%  Jan 2010


disp(' ');
disp('  **********  K-SVD Test Demo  **********');



% dictionary dimensions
n = 256;
m = 900;

% number of examples
L = 900;

% sparsity of each example
k = 8;

% noise power (dB)
snr = 20;



%% generate random dictionary and data %%
seg=0;

for N=1:450
    
s1 = wavread('male_src_1.wav');

s2 = wavread('male_src_2.wav');

s3 = wavread('male_src_3.wav');

s4 = wavread('male_src_4.wav');
  

s1 = s1(seg+1:seg+256); s2 = s2(seg+1:seg+256); s3 = s3(seg+1:seg+256); s4 = s4(seg+1:seg+256);


mixing = [0.3420, 0.6428, 0.7934, 0.9239; ...
          0.9397, 0.7660, 0.6088, 0.3827]; 
 
       
mixture = [s1 s2 s3 s4] * mixing';

m1=mixture(:,1);
window = hamming(31);
M1 = spectrogram(m1,window,16,31,8000);
M1 = reshape(M1,256,1);
M1 = abs(M1);
m2=mixture(:,2);  
M2 = spectrogram(m2,window,16,31,8000);
M2 = reshape(M2,256,1);
M2 = abs(M2);
mixture= [M1,M2];

if seg==0
    X=mixture;
else
    X=[X,mixture];
end
seg=seg+256;
end

%% run k-svd training %%

params.data = X;
params.Tdata = k;
params.dictsize = 900;
params.iternum = 30;
params.memusage = 'high';
%params.Tdict= k;

[Dksvd,g,err] = ksvd(params,'');


%% show results %%

