function [E,X] = test_ksvd (D,filename)
% funkce pro testovani natrenovaneho slovniku
%D natrenovany slovnik, filename - testovaci signal,
m = size(D,1);
o = size (D,2);
t = 1/(48000/m);
A = cut(filename,t);
X = zeros(o,size(A,2));
parameters.StopMaxiter=o;
for i=1:o %odhad X pomoci OMP - pro i od 1 do poctu sloupcu v Y
        X(:,i)=omp(D,A(:,i),parameters);% i-ty sloupec z X pouzij OMP
        disp(sprintf('%d-th iteration OMP',i));
end
[B,I] = sort (abs(X),'descend');
X_s = zeros (size (X));
E = zeros(1,o); %prazdny vektor 
for p = 1:size(X,1) %iterace po radcich
    for s = 1:size(X,2) %iterace po sloupcich
         x_s = X_s(:,s); %s-ty vekotr z X_s
         x = X(:,s);
         i_s = I(:,s); %s-ty vektor z I
         x_s(i_s(p)) = x(i_s(p)); %serazeni
         X_s(:,s)=x_s; %ulozeni sloupce do matice
    end
    E (p) = norm(A-(D*X_s),'fro'); %vypocet p-te chyby
end
end