Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tff2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
skmad-suite
tff2020
Commits
bd022f0f
Commit
bd022f0f
authored
5 years ago
by
Marina Kreme
Browse files
Options
Downloads
Patches
Plain Diff
delete file
parent
85c45155
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/tfgm/scripts/solve_all_Narea_algo2.m
+0
-348
0 additions, 348 deletions
matlab/tfgm/scripts/solve_all_Narea_algo2.m
with
0 additions
and
348 deletions
matlab/tfgm/scripts/solve_all_Narea_algo2.m
deleted
100644 → 0
+
0
−
348
View file @
85c45155
clc
;
clear
;
close
all
;
%Algo 2 pour toutes les simuls
%%
pwd
;
pathname
=
'all_sig_Nareas'
;
if
~
exist
(
'all_sig_Nareas'
,
'dir'
)
mkdir
(
'all_sig_Nareas'
);
end
addpath
(
'all_sig_Nareas'
)
%%
f
=
fopen
(
'exp_Narea.csv'
,
'w'
);
fprintf
(
f
,
'%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s \n'
,
'loc_src'
,
'wb_src'
,
...
,
'win_type'
,
'win_len'
,
't_oracle'
,
't_true_energy'
,
't_est'
,
't_arrf'
,
...
,
't_evdn'
,
't_ut_x'
,
'sdr_mix'
,
'sdr_interp'
,
'sdr_zero'
,
'sdr_est'
,
...
,
'sdr_oracle'
);
%%
resampling_fs
=
8000
;
% sampling frequency
sig_len
=
16384
;
target_name
=
{
'car'
,
'plane'
,
'train'
};
per_name
=
{
'beeps'
,
'bird'
,
'clicks'
,
'pop'
};
win_type_list
=
{
'gauss'
,
'hann'
};
win_len_list
=
[
256
,
512
];
%%
for
w
=
1
:
1
%length(win_type_list)
win_type
=
win_type_list
{
w
};
win_len
=
win_len_list
(
w
);
params
=
get_params
(
win_len
,
win_type
);
for
ind_wd
=
1
:
1
%length(target_name)
fprintf
(
"**************************************\n\n"
)
fprintf
(
"I'am in the %.f ieme run. target source is:%s \n"
,
ind_wd
,
target_name
{
ind_wd
});
fprintf
(
"**************************************\n\n"
)
for
ind_loc
=
1
:
1
%length(per_name)
fprintf
(
"Perturbation source number %.f : %s \n"
,
ind_loc
,
per_name
{
ind_loc
})
;
fprintf
(
"**************************************\n\n"
)
[
radius
,
gain_mix_db
,
gain_loc_db
,
deb
]
=
set_smooth_mask_params
(
ind_wd
,
ind_loc
,
win_type
);
win_len
=
params
.
win_len
;
win_type
=
params
.
win_type
;
hop
=
params
.
hop
;
nbins
=
params
.
nbins
;
deb_ind_wd
=
0
;
deb_ind_loc
=
deb
;
or_mask
=
1
;
approx_win_len
=
win_len
;
[
signals
,
dgt_params
,
signal_params
,
mask_bool
,
dgt
,
idgt
]
=
get_mix
(
ind_loc
,
...
,
ind_wd
,
deb_ind_loc
,
deb_ind_wd
,
resampling_fs
,
sig_len
,
...
,
approx_win_len
,
hop
,
nbins
,
win_type
,
gain_mix_db
,
gain_loc_db
,
radius
,
or_mask
);
fprintf
(
"We work with %s window of length %.f\n"
,
win_type
,
win_len
);
fprintf
(
"Gabor transform parameters are: \n"
)
fprintf
(
'hop :%2.f\n'
,
dgt_params
.
hop
);
fprintf
(
'n_bins: %2.f\n'
,
dgt_params
.
nbins
);
%%
figure
;
% window plot
plot_win
(
dgt_params
.
win
,
signal_params
.
fs
,
signal_params
.
sig_len
,
win_type
)
title
([
num2str
(
win_type
),
' - window'
]);
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
num2str
(
win_type
),
'_window.png'
]));
% mask plot
[
mask_area
,
mask_area_ratio
]
=
get_mask_area
(
mask_bool
);
figure
(
'name'
,
'mask'
);
plot_spectrogram
(
mask_bool
,
dgt_params
,
signal_params
,
dgt
);
title
([
'mask : mask-area = '
,
num2str
(
mask_area
)]);
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
num2str
(
win_type
),
'_mask.png'
]));
%%
tol_subregions
=
1e-5
;
[
mask_labeled
,
n_areas
]
=
get_nareas
(
mask_bool
,
dgt
,
idgt
,
dgt_params
,
...
,
signal_params
,
tol_subregions
);
[
gabmul_list
,
mask_list
]
=
get_P_gabmul
(
mask_labeled
,
dgt
,
idgt
);
%% compute EVD decomposition
%Halko params
tolerance_arrf
=
1e-3
;
proba_arrf
=
1
-
1e-4
;
x_mix
=
signals
.
mix
;
% mix
masks
=
mask_list
;
% compute EVD usisng Halko
[
t_arrf
,
t_evdn
,
t_ut_x
,
rank_q
,
s_vec_list
,
u_mat_list
,
ut_x_list
,
...
,
r
]
=
compute_decomposition
(
x_mix
,
masks
,
gabmul_list
,
tolerance_arrf
,
proba_arrf
);
fprintf
(
"Estimated rank is : %.f \n"
,
rank_q
);
%% Plot eigenvalues
figure
;
for
k
=
1
:
n_areas
txt
=
[
'sub-region ='
num2str
(
k
)];
plot
(
s_vec_list
{
k
},
'LineWidth'
,
3
,
'DisplayName'
,
txt
);
hold
on
;
end
xlabel
(
'$k$'
,
'Interpreter'
,
'latex'
);
ylabel
(
'$\sigma[k]$'
,
'Interpreter'
,
'latex'
);
set
(
gca
,
'YScale'
,
'log'
);
grid
;
legend
show
;
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
xlabel
(
'$k$'
,
'Interpreter'
,
'latex'
);
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
...
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
'gabmul_eigenvalues.png'
]));
%% find optimal lambda (best SDR)
x_target
=
signals
.
target
;
[
lambda_oracle
,
t_oracle
]
=
compute_lambda_oracle_sdr
(
x_target
,
x_mix
,
...
,
s_vec_list
,
u_mat_list
,
ut_x_list
);
fprintf
(
"Running time to tune lambda (oracle): %f \n"
,
t_oracle
);
%% estimate energy and lambda -our method
[
lambda_est
,
t_est
]
=
compute_lambda
(
x_mix
,
mask_labeled
,
dgt_params
,
...
,
signal_params
,
dgt
,
s_vec_list
,
u_mat_list
,
ut_x_list
,
...
,
gabmul_list
);
fprintf
(
"Running time to tune lambda (est): %f \n"
,
t_est
);
%% estimate lambda from true energy
n_areas
=
length
(
s_vec_list
);
e_target_true_energy
=
zeros
(
n_areas
,
1
);
x_engine_tf_mat
=
dgt
(
gabmul_list
{
1
}(
x_target
));
for
k_area
=
1
:
n_areas
mask_k
=
(
mask_labeled
==
k_area
);
x_engine_tf_masked
=
mask_k
.*
x_engine_tf_mat
;
e_target_true_energy
(
k_area
)
=
norm
(
x_engine_tf_masked
,
'fro'
)
.^
2
;
end
e_target
=
e_target_true_energy
;
[
lambda_true_energy
,
t_true_energy
]
=
compute_lambda
(
x_mix
,
mask_labeled
,
dgt_params
,
...
,
signal_params
,
dgt
,
s_vec_list
,
u_mat_list
,
ut_x_list
,
...
,
gabmul_list
,
e_target
);
fprintf
(
"Running time to tune lambda (True): %f \n"
,
t_true_energy
);
%% Results
x_est
=
@
(
lambda_coef
)
compute_estimate
(
lambda_coef
,
x_mix
,
s_vec_list
,
u_mat_list
,
ut_x_list
);
x_engine
=
signals
.
target
;
sdr_engine
=
@
(
lambda_coef
)
sdr
(
x_engine
,
x_est
(
lambda_coef
));
%
tf_mat_mix
=
compute_dgt
(
signals
.
mix
,
dgt
);
%interpolation
x_interp
=
solver_tfgm_interp
(
tf_mat_mix
,
mask_bool
,
idgt
);
%zero fill
x_zero
=
solver_tfgm_zero
(
tf_mat_mix
,
mask_bool
,
idgt
);
sdr_zero
=
sdr
(
x_engine
,
x_zero
);
sdr_interp
=
sdr
(
x_engine
,
x_interp
);
%%
figure
;
l_range
=
10.
^
(
linspace
(
-
10
,
10
,
100
));
sdr_engine_l
=
zeros
(
length
(
l_range
),
1
);
for
l
=
1
:
length
(
l_range
)
sdr_engine_l
(
l
)
=
sdr_engine
(
l_range
(
l
));
end
semilogx
(
l_range
,
sdr_engine_l
,
'-'
,
'LineWidth'
,
3
);
hold
on
;
semilogx
(
l_range
,
sdr_engine
(
lambda_oracle
)
*
ones
(
length
(
l_range
),
1
),
'r-'
,
'LineWidth'
,
3
)
semilogx
(
l_range
,
sdr_engine
(
lambda_est
)
*
ones
(
length
(
l_range
),
1
),
'm-'
,
'LineWidth'
,
3
)
%semilogx(l_range,sdr_engine(lambda_true_energy)*ones(length(l_range),1), 'g-','LineWidth',3)
semilogx
(
l_range
,
sdr_zero
*
ones
(
length
(
l_range
),
1
),
'c-'
,
'LineWidth'
,
3
);
semilogx
(
l_range
,
sdr_interp
*
ones
(
length
(
l_range
),
1
),
'b-'
,
'LineWidth'
,
3
);
xlabel
(
'$\lambda$'
,
'Interpreter'
,
'latex'
)
ylabel
(
'SDR(dB)'
)
set
(
gca
,
'XScale'
,
'log'
);
grid
on
;
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
legend
(
'SDR'
,
'Oracle SDR'
,
'Estimate'
,
'Zerofill'
,
...
,
'Interp'
,
'Location'
,
'southeast'
)
%% Reconstructed signals
x_oracle
=
x_est
(
lambda_oracle
);
wav_write
(
'x_oracle.wav'
,
x_oracle
,
signal_params
.
fs
);
x_rec
=
x_est
(
lambda_est
);
wav_write
(
'x_est.wav'
,
x_rec
,
signal_params
.
fs
);
x_true_energy
=
x_est
(
lambda_true_energy
);
wav_write
(
'x_true_energy.wav'
,
x_true_energy
,
signal_params
.
fs
);
x_zero
=
solver_tfgm_zero
(
tf_mat_mix
,
mask_bool
,
idgt
);
wav_write
(
'x_zero_fill.wav'
,
x_zero
,
signal_params
.
fs
);
%x_interp
x_interp
=
solver_tfgm_interp
(
tf_mat_mix
,
mask_bool
,
idgt
);
wav_write
(
'x_interp.wav'
,
x_interp
,
signal_params
.
fs
);
%sdr
sdr_oracle
=
sdr
(
x_engine
,
x_oracle
);
sdr_rec
=
sdr
(
x_engine
,
x_rec
);
sdr_true_energy
=
sdr
(
x_engine
,
x_true_energy
);
sdr_zero
=
sdr
(
x_engine
,
x_zero
);
sdr_interp
=
sdr
(
x_engine
,
x_interp
);
sdr_mix
=
sdr
(
x_engine
,
x_mix
);
%% Itakura saito
% is_true = itakura_saito_dist_spectrum(x_target,x_true_energy);
% is_zero = itakura_saito_dist_spectrum(x_target,x_zero) ;
% is_mix= itakura_saito_dist_spectrum(x_target,x_mix) ;
% is_tff= itakura_saito_dist_spectrum(x_target,x_rec) ;
% is_interp= itakura_saito_dist_spectrum(x_target,x_interp);
%
%%
% print
fprintf
(
'Oracle lambda: %f\n'
,
lambda_oracle
);
fprintf
(
'True-energy lambda: %f \n'
,
lambda_true_energy
);
fprintf
(
'Estimated lambda: %f \n'
,
lambda_est
);
fprintf
(
'SDR for oracle lambda: %f dB\n'
,
sdr_oracle
);
fprintf
(
'SDR for estimated lambda: %f dB\n'
,
sdr_rec
);
fprintf
(
'SDR for true-energy lambda: %f dB\n'
,
sdr_true_energy
);
fprintf
(
'Zero filling SDR: %f dB\n'
,
sdr_zero
);
fprintf
(
'Mix SDR: %f dB \n'
,
sdr_mix
);
fprintf
(
'Interp + random phases filling SDR: %e dB\n'
,
sdr_interp
);
%%
x_per
=
signals
.
noise
;
figure
;
plot_spectrogram
(
x_mix
,
dgt_params
,
signal_params
,
dgt
)
title
([
'Mix SDR='
,
num2str
(
sdr_mix
),
'dB'
]);
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'mix.pdf'
]));
figure
;
plot_spectrogram
(
x_target
,
dgt_params
,
signal_params
,
dgt
);
title
([
'True source -'
,
target_name
{
ind_wd
}])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_true_wb_source.pdf'
]));
figure
;
plot_spectrogram
(
x_per
,
dgt_params
,
signal_params
,
dgt
);
title
([
'Pertur -'
,
per_name
{
ind_loc
}])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_true_wb_source.pdf'
]));
figure
;
plot_spectrogram
(
x_zero
,
dgt_params
,
signal_params
,
dgt
)
title
([
'Zero fill SDR= '
,
num2str
(
sdr_zero
),
'dB'
])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_zero_fill.pdf'
]));
figure
;
plot_spectrogram
(
x_oracle
,
dgt_params
,
signal_params
,
dgt
)
title
([
'\lambda_{opt} SDR= '
,
num2str
(
sdr_oracle
),
'dB'
])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_oracle_sdr.pdf'
]));
figure
;
plot_spectrogram
(
x_rec
,
dgt_params
,
signal_params
,
dgt
)
title
([
'Estimated \lambda SDR= '
,
num2str
(
sdr_rec
),
'dB'
])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_tff_estimate.pdf'
]));
figure
;
plot_spectrogram
(
x_true_energy
,
dgt_params
,
signal_params
,
dgt
)
title
([
'True energy \lambda SDR= '
,
num2str
(
sdr_true_energy
),
'dB'
])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_oracle_true_energy.pdf'
]));
figure
;
plot_spectrogram
(
x_interp
,
dgt_params
,
signal_params
,
dgt
)
title
([
'interp SDR= '
,
num2str
(
sdr_interp
),
'dB'
])
set
(
gca
,
'FontSize'
,
20
,
'fontName'
,
'Times'
);
saveas
(
gcf
,
fullfile
(
pathname
,
[
target_name
{
ind_wd
},
'_'
per_name
{
ind_loc
},
'_'
,
'spectrogram_interp.pdf'
]));
%%
fprintf
(
f
,
'%s %s %s %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f \n'
,
...
,
target_name
{
ind_wd
},
per_name
{
ind_loc
},
win_type_list
{
w
},
win_len_list
(
w
),
t_oracle
,
t_true_energy
,
...
,
t_est
,
t_arrf
,
t_evdn
,
t_ut_x
,
sdr_mix
,
sdr_interp
,
...
,
sdr_zero
,
sdr_rec
,
sdr_oracle
);
%%
file_name
=
[
'exp_Nregions'
,
target_name
{
ind_wd
},
'_'
,
per_name
{
ind_loc
},
'_'
,
'.mat'
];
save
(
file_name
,
'ind_wd'
,
'ind_loc'
,
'resampling_fs'
,
'sig_len'
,
'radius'
,
...
,
'deb_ind_loc'
,
'deb_ind_wd'
,
'win_len'
,
'win_type'
,
'signals'
,
'dgt_params'
,
...
,
'signal_params'
,
'mask_bool'
,
'dgt'
,
'idgt'
,
'mask_area'
,
'mask_area_ratio'
,
...
,
'gabmul_list'
,
'mask_list'
,
'tolerance_arrf'
,
'proba_arrf'
,
't_arrf'
,
't_evdn'
,
...
,
't_ut_x'
,
'rank_q'
,
's_vec_list'
,
'u_mat_list'
,
'ut_x_list'
,
'r'
,
...
.,
'lambda_est'
,
't_true_energy'
,
'e_target_true_energy'
,
'e_target'
,
'lambda_true_energy'
,
...
,
'lambda_oracle'
,
't_oracle'
,
'x_oracle'
,
'x_rec'
,
'x_true_energy'
,
'x_zero'
,
...
,
'x_interp'
,
'sdr_mix'
,
'sdr_oracle'
,
'sdr_true_energy'
,
'sdr_zero'
,
'sdr_interp'
);
end
end
end
fclose
(
f
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment