Skip to content
Snippets Groups Projects
Commit 8acbc0fb authored by Marina Kreme's avatar Marina Kreme
Browse files

refactor - fix bugs

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