58 lines
2.1 KiB
Mathematica
58 lines
2.1 KiB
Mathematica
|
function [D_k, A_k] = nmf(S, D_0, A_0, ite, pas, filename, valeurs_t, valeurs_f, R)
|
||
|
|
||
|
delete("/work/lfainsin-matlab/TP12/" + filename + "_sono_" + num2str(R) + ".gif");
|
||
|
delete("/work/lfainsin-matlab/TP12/" + filename + "_dico_" + num2str(R) + ".gif");
|
||
|
delete("/work/lfainsin-matlab/TP12/" + filename + "_activ_" + num2str(R) + ".gif");
|
||
|
|
||
|
figure('units', 'normalized', 'outerposition', [0 0 1 1]);
|
||
|
|
||
|
eps = 10^ - 3;
|
||
|
A_k = A_0 .* max(D_0)';
|
||
|
D_k = D_0 ./ max(D_0);
|
||
|
|
||
|
for i = 1:ite
|
||
|
|
||
|
A_kp1 = A_k .* (D_k' * S) ./ ((D_k' * D_k) * A_k + eps);
|
||
|
D_kp1 = D_k .* (S * A_k') ./ (D_k * (A_k * A_k') + eps);
|
||
|
|
||
|
A_k = A_kp1 .* max(D_kp1)';
|
||
|
D_k = D_kp1 ./ max(D_kp1);
|
||
|
|
||
|
if rem(i, pas) == 0
|
||
|
|
||
|
imagesc(1:R, valeurs_f, 20 * log10(abs(D_k)));
|
||
|
set(gca, 'xtick', 1:R)
|
||
|
caxis([-40 10]);
|
||
|
axis xy;
|
||
|
xlabel('Composantes');
|
||
|
ylabel('Frequence (Hz)');
|
||
|
title("$\mathbf{D_{" + num2str(i) + "}}$", 'Interpreter', 'Latex');
|
||
|
drawnow;
|
||
|
export_fig(gcf, "/work/lfainsin-matlab/TP12/" + filename + "_dico_" + num2str(R) + ".gif", '-png', '-painters', '-m2', '-append', '-delay', 10);
|
||
|
|
||
|
imagesc(valeurs_t, 1:R, A_k);
|
||
|
set(gca, 'ytick', 1:R)
|
||
|
axis xy;
|
||
|
xlabel('Temps (s)');
|
||
|
ylabel('Composantes');
|
||
|
title("$\mathbf{A_{" + num2str(i) + "}}$", 'Interpreter', 'Latex');
|
||
|
drawnow;
|
||
|
export_fig(gcf, "/work/lfainsin-matlab/TP12/" + filename + "_activ_" + num2str(R) + ".gif", '-png', '-painters', '-m2', '-append', '-delay', 10);
|
||
|
|
||
|
prod = 20 * log10(abs(D_k * A_k) + eps);
|
||
|
imagesc(valeurs_t, valeurs_f, prod);
|
||
|
axis xy;
|
||
|
xlabel('Temps (s)');
|
||
|
ylabel('Frequence (Hz)');
|
||
|
title("$\mathbf{S_{" + num2str(i) + "}}$", 'Interpreter', 'Latex');
|
||
|
drawnow;
|
||
|
export_fig(gcf, "/work/lfainsin-matlab/TP12/" + filename + "_sono_" + num2str(R) + ".gif", '-png', '-painters', '-m2', '-append', '-delay', 10);
|
||
|
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
% ffmpeg -i input.mp3 -ac 1 output.wav
|