clear; close all; taille_ecran = get(0, 'ScreenSize'); L = taille_ecran(3); H = taille_ecran(4); % Lecture des fichiers séparés : [y_h, f_ech] = audioread('Musiques/violon.wav'); [y_p, f_ech] = audioread('Musiques/batterie.wav'); % Création du mélange : taille = min(length(y_h), length(y_p)); y_h = y_h(1:taille); y_p = y_p(1:taille); y = y_h + y_p; % Passage dans le domaine fréquentiel : n_fenetre = 1024; % Largeur de la fenêtre (en nombre de points) n_decalage = 512; % Décalage entre deux fenêtres (en nombre de points) fenetre = 'hann'; % Type de la fenêtre [Y_h, valeurs_t, valeurs_f] = TFCT(y_h, f_ech, n_fenetre, n_decalage, fenetre); S_h = 20 * log10(abs(Y_h) + eps); [Y_p, valeurs_t, valeurs_f] = TFCT(y_p, f_ech, n_fenetre, n_decalage, fenetre); S_p = 20 * log10(abs(Y_p) + eps); [Y, valeurs_t, valeurs_f] = TFCT(y, f_ech, n_fenetre, n_decalage, fenetre); S = 20 * log10(abs(Y) + eps); % Séparation harmonique/percussive : [F_h, F_p] = HPSS(abs(Y).^2); % Création des masques : % M_h = F_h >= F_p; % M_p = F_p > F_h; M_h = F_h ./ (F_h + F_p); M_p = F_p ./ (F_h + F_p); % Application des masques : Y_h_hat = M_h .* Y; Y_p_hat = M_p .* Y; % Retour dans le domaine temporel : [y_h_hat, ~] = ITFCT(Y_h_hat, f_ech, n_decalage, fenetre); [y_p_hat, ~] = ITFCT(Y_p_hat, f_ech, n_decalage, fenetre); % Normalisation : y_h_hat = min(max(y_h_hat, -1), 1); y_p_hat = min(max(y_p_hat, -1), 1); % Sauvegarde : audiowrite('/work/lfainsin-matlab/TP12/exo1_HPSS_harmonique.wav', y_h_hat, f_ech); audiowrite('/work/lfainsin-matlab/TP12/exo1_HPSS_percussive.wav', y_p_hat, f_ech); audiowrite('/work/lfainsin-matlab/TP12/exo1_combined.wav', y, f_ech); % Figures : figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, S_h); caxis([-40 20]); axis xy; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{S}_{h}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_h.png", '-png', '-painters', '-m2'); figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, S_p); caxis([-40 20]); axis xy; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{S}_{p}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_p.png", '-png', '-painters', '-m2'); % Sonagramme du mélange : figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, S); caxis([-40 20]); axis xy; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{S}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_mélange.png", '-png', '-painters', '-m2'); % Sonagramme filtrés : figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, log10(F_h)); axis xy; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{F}_{h}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_filter_h.png", '-png', '-painters', '-m2'); figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, log10(F_p)); axis xy; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{F}_{p}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_filter_p.png", '-png', '-painters', '-m2'); % Affichage des masques : figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, M_h); axis xy; axis tight; colormap gray; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{M}_{h}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_mask_h.png", '-png', '-painters', '-m2'); figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, M_p); axis xy; axis tight; colormap gray; xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\mathbf{M}_{p}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_mask_p.png", '-png', '-painters', '-m2'); % Affichage des sonagrammes masqués : figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, 20 * log10(abs(Y_h_hat + eps))); axis xy; axis tight; caxis([-40 20]); xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\hat{\mathbf{S}}_{h}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_masked_h.png", '-png', '-painters', '-m2'); figure('units', 'normalized', 'outerposition', [0 0 1 1]); imagesc(valeurs_t, valeurs_f, 20 * log10(abs(Y_p_hat + eps))); axis xy; axis tight; caxis([-40 20]); xlabel('Temps (s)'); ylabel('Frequence (Hz)'); title('$\hat{\mathbf{S}}_{p}$', 'Interpreter', 'Latex'); drawnow; export_fig(gcf, "/work/lfainsin-matlab/TP12/exo1_sono_masked_p.png", '-png', '-painters', '-m2');