Commit 8acbc0fb authored by Marina Kreme's avatar Marina Kreme
Browse files

refactor - fix bugs

parent e066bb17
Pipeline #5960 passed with stage
in 6 minutes and 16 seconds
clc; clear; close all;
%%
% Generate all combination between wide-band and localized signals
%%
make_wav_pairs()
% This script allows to generate all the possible mixtures as well as
% the parameters for the corresponding masks for each window.
%%
pwd;
pathname ='spectro_all_mixtures';
if ~exist('spectro_all_mixtures','dir')
mkdir('spectro_all_mixtures');
pathname ='fig_spectro_all_mixtures';
if ~exist(pathname,'dir')
mkdir(pathname);
end
addpath('spectro_all_mixtures')
addpath(pathname)
%%
data = load('signal_lists.mat');
dataset = get_dataset();
dbstack;
%%
resampling_fs = 8000;
sig_len =16384;
signal_params = generate_signal_parameters(resampling_fs, sig_len);
%% DGT parameters
approx_win_len = 512;
win_len = approx_win_len;
win_type='hann';
params = get_params(win_len, win_type);
dgt_params = generate_dgt_parameters(win_type, approx_win_len, params.hop, params.nbins, sig_len);
%% DGT operators
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
wins_params = struct('Gauss256', struct('win_type','gauss','win_len', 256),...,
'Hann512', struct('win_type','hann','win_len', 512));
gamma=0.7;
fs = 8000;
sig_len =16384;
signal_params = generate_signal_parameters(fs, sig_len);
%% All mix
close all
target_name ={'car','plane','train'};
per_name = {'beeps','bird','clicks','pop'};
%%
wideband_name ={'car','plane','train'};
localized_name = {'beeps','bird','chirps','clicks','finger_snaps','modulations'};
gamma=0.7;
deb=0;
close all;
for k=1:length(data.wide_band_sources_files)
sig_wd = load_wideband_signal(k, resampling_fs, sig_len);
%% DGT parameters
keys = fieldnames(wins_params);
for win_param = 1: length(keys)
for l=1:length(data.localized_sources_files)
%%
%figure;
sig_loc = load_localized_signal(l, resampling_fs, sig_len,deb);
signals = generate_mix_signal(sig_wd, sig_loc, gamma);
tf_mat_target = compute_dgt(signals.wideband, dgt );
tf_mat_per = compute_dgt(signals.localized, dgt );
tf_mat_mix = compute_dgt(signals.mix, dgt );
[alpha, seuil, radius] = set_smooth_mask_params(target_name{k}, per_name{l}, win_type);
sdr_mix = sdr(signals.wideband, signals.mix);
[original_mask, mask_after_imclose, mask_after_imopen,...,
mask] = generate_mask(tf_mat_target, tf_mat_per, alpha, seuil, radius);
subplot(221);
plot_spectrogram(tf_mat_target, dgt_params, signal_params, dgt )
title(target_name{k})
subplot(222);
plot_spectrogram(tf_mat_per, dgt_params, signal_params, dgt )
title(per_name(l));
subplot(223);
plot_spectrogram(tf_mat_mix, dgt_params, signal_params, dgt )
title(['Mix SDR= ',num2str(sdr_mix),'dB']);
subplot(224);
plot_spectrogram(mask, dgt_params, signal_params, dgt )
title(['mask - ', num2str(win_type)]);
saveas(gcf,fullfile(pathname, [target_name{k},'_' num2str(l), '_',num2str(win_type) '.png']));
% figure;
% plot_spectrogram((1-mask).*tf_mat_per, dgt_params, signal_params, dgt );
% title(['masked spectro - ', target_name{k}, per_name(l)])
%saveas(gcf,fullfile(pathname, ['masked_spectro_', target_name{k},'_' num2str(l), '_',num2str(win_type) '.png']));
end
win_len = wins_params.(keys{win_param}).win_len;
win_type = wins_params.(keys{win_param}).win_type;
params = get_params(win_len, win_type);
fprintf("window %s:\n\n",win_type);
% DGT parameters
dgt_params = generate_dgt_parameters(win_type, win_len, params.hop,...,
params.nbins, sig_len);
%DGT operators
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
for wb = 1:length(wideband_name)
wideband_src =wideband_name{wb};
for loc = 1:length(localized_name)
loc_source = localized_name{loc};
[x_loc, fs_loc]= audioread(dataset.localized.(loc_source));
[x_wb, fs_wb]= audioread(dataset.wideband.(wideband_src));
if length(x_loc)~=length(x_wb)
warning('Arrays are not equal');
end
if fs_loc~=fs_wb
error('The sampling frequencies must be the same.')
end
signals = generate_mix_signal(x_wb, x_loc, gamma);
tf_mat_wb = dgt(signals.wideband);
tf_mat_loc = dgt(signals.localized);
tf_mat_mix = dgt(signals.mix);
[alpha, thres, radius] = set_smooth_mask_params(wideband_src,...,
loc_source, win_type);
[mask] = generate_mask(tf_mat_wb, tf_mat_loc, alpha, thres, radius);
figure ;
subplot(221)
plot_spectrogram(tf_mat_wb, dgt_params, signal_params, dgt );
title('wideband')
subplot(222)
plot_spectrogram(tf_mat_loc, dgt_params, signal_params, dgt );
title('localized')
subplot(223)
plot_spectrogram(tf_mat_mix, dgt_params, signal_params, dgt );
title('mix')
subplot(224)
plot_spectrogram(mask, dgt_params, signal_params, dgt );
title('mask')
end
end
end
......@@ -64,8 +64,8 @@ dgt_params = generate_dgt_parameters(win_type, approx_win_len, hop,...,
%% generate binary mask
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
tf_mat_wb = compute_dgt(signals.wideband, dgt );
tf_mat_loc = compute_dgt(signals.localized, dgt );
tf_mat_wb = dgt(signals.wideband);
tf_mat_loc = dgt(signals.localized);
[mask, original_mask, mask_after_imclose, mask_after_imopen,...,
] = generate_mask(tf_mat_wb, tf_mat_loc, alpha, thres, radius);
......
function [alpha, thres, radius] = set_smooth_mask_params(wideband_src, loc_source, win_type)
function [alpha, thres, radius] = set_smooth_mask_params(wideband_src, loc_source, win_type)
% This function allow us to generate parameters for smooth binary mask
% Inputs:
% - wideband_src : signal with wide-bande spectrogram
......@@ -31,6 +31,11 @@ switch win_type
thres=1e-4;
radius=4;
case 'chirps'
alpha=0.1;
thres=0.0001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0002;
......@@ -40,14 +45,12 @@ switch win_type
alpha=0.01;
thres=0.0001;
radius=1;
case 'modulations'
alpha=1;
thres=0.0002;
radius=3;
case 'pop'
alpha=0.1;
thres=0.0001;
radius=1;
end
case'plane'
......@@ -63,22 +66,26 @@ switch win_type
thres=0.0001;
radius=1;
case 'chirps'
alpha=0.01;
thres=0.0001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0002;
radius=4;
case 'finger_snaps'
alpha=0.01;
thres=0.0001;
radius=1;
case 'modulations'
alpha=1;
thres=0.0002;
radius=3;
case 'pop'
alpha=0.01;
thres=0.0001;
radius=1;
end
......@@ -94,23 +101,25 @@ switch win_type
alpha=0.1;
thres=0.0001;
radius=3;
case 'chirps'
alpha=0.01;
thres=0.001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0002;
radius=4;
case 'finger_snaps'
alpha=0.01;
thres=0.0001;
radius=1;
case 'modulations'
alpha=1;
thres=0.0002;
radius=3;
case 'pop'
alpha=0.01;
thres=0.001;
radius=1;
end
end
......@@ -133,6 +142,11 @@ switch win_type
thres=0.0001;
radius=3;
case 'chirps'
alpha=0.1;
thres=0.0001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0002;
......@@ -145,10 +159,6 @@ switch win_type
alpha=1;
thres=0.0002;
radius=3;
case 'pop'
alpha=1;
thres=0.0002;
radius=4;
end
case 'plane'
......@@ -164,6 +174,11 @@ switch win_type
thres=0.0002;
radius=4;
case 'chirps'
alpha=0.1;
thres=0.0001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0002;
......@@ -177,10 +192,7 @@ switch win_type
alpha=1;
thres=0.0002;
radius=3;
case 'pop'
alpha=1;
thres=0.0002;
radius=1;
end
case 'train'
switch loc_source
......@@ -193,6 +205,10 @@ switch win_type
alpha=1;
thres=0.001;
radius=2;
case 'chirps'
alpha=0.1;
thres=0.0001;
radius=1;
case 'clicks'
alpha=1;
thres=0.0001;
......@@ -205,11 +221,7 @@ switch win_type
alpha=1;
thres=0.0002;
radius=3;
end
end
end
fprintf("The parameters for smoothing the mask are: \n")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment