Commit bf42dfd8 authored by Marina Kreme's avatar Marina Kreme
Browse files

tests halko function

parent ab24eb16
clc; clear; close all;
% Ce script permet de tester la fonction qui genere le multiplicateur de Gabor.
% et de faire des tests permettant de verifier ses proprietes
%%
win_type='hann';
approx_win_len=128;
hop = approx_win_len/8;
nbins = approx_win_len*2;
sig_len=1024;
fs=1;
%% Les parametres du signal
signal_params = generate_signal_parameters(fs, sig_len);
dgt_params = generate_dgt_parameters(win_type, approx_win_len, hop, nbins, sig_len);
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
%% A ton adjoint_stft(direct_stft(x)) = x? c'est-a dire la propriete de tight frame ?
x =randn(sig_len,1);
test = idgt(dgt(x));
disp(norm(test-x,2))
%% Le mask
% dimension de la TFCT
M = dgt_params.nbins/2 +1;
N = signal_params.sig_len/ dgt_params.hop;
T= duration;
t_lim = [0.3, 0.5];
f_lim =[0.1, 0.2];
mask = generate_rectangular_mask(nbins, hop, sig_len, t_lim, f_lim);
figure; plotdgtreal(mask, dgt_params.hop, dgt_params.nbins,fs)
%% Generation du multiplicateur et verification de la propit de symetrie
mul1 = gen_gabmul_operator(dgt, idgt, mask);
mask1 = conj(mask);
mul2 = gen_gabmul_operator(dgt, idgt, mask1);
disp(norm(mul1(x)-mul2(x))) %verifie la symetrie
%% Si mask_id = I, a t-on mul1(x)=x ?;
mask_id = zeros(M,N);
mul_id = gen_gabmul_operator(dgt, idgt, mask_id);
Mul = mul_id(x);
disp(norm(Mul-x,2))
%% diagonalisation : mul1 est-elle une matrice SDP ?
[U,D] = eigs(mul1,signal_params.sig_len, signal_params.sig_len);
%% SDP
fprintf("test de positivite des valeus propres \n")
disp(diag(D)>=0);
%% Verifier si U est bien unitaire
%%
fprintf("test de normalite des vecteurs propres \n")
disp(norm(U*U',2))
disp(norm(U'*U,2))
figure; imagesc(abs(U*U') -eye(1024))
max(max(abs(U*U' )-eye(1024)))
clc; clear; close all;
%%
% This script tests the generation of the DGT parameters
%%
win_type='hann';
approx_win_len=256;
hop = approx_win_len/8;
nbins = approx_win_len*2;
sig_len=16384;
dgt_params = generate_dgt_parameters(win_type, approx_win_len, hop, nbins, sig_len);
%%
fprintf(['Les parametres de la DGT sont:\n win_type = %s\n',...,
' hop=%.2f\n nbins=%.2f\n win_len=%.4f\n'],...,
dgt_params.win_type, dgt_params.hop, dgt_params.nbins,...,
dgt_params.win_len);
clc; clear; close all;
%%
%script test pour le mask
%%
wideband_src='car';
loc_source='bird';
win_type='hann';
approx_win_len = 512;
hop = approx_win_len/8;
nbins = approx_win_len*2;
sig_len=16384;
fs=8000;
signal_params= generate_signal_parameters(fs, sig_len);
alpha=1;
seuil=0.01;
radius=2;
dgt_params = generate_dgt_parameters(win_type, approx_win_len, hop, nbins, sig_len);
%%
ind_wideband=1;
ind_localized=2;
deb=0;
[x_wideband,x_localized] = load_pairs(ind_wideband, ind_localized, fs, sig_len, deb);
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
%%
tf_mat_wideband = compute_dgt(x_wideband,dgt);
tf_mat_loc=compute_dgt(x_localized,dgt);
[mask, original_mask, mask_after_imclose]= generate_mask(tf_mat_wideband, tf_mat_loc, alpha, seuil, radius);
%%
figure;
plot_mask(original_mask, hop, nbins, fs);
title('Original mask');
%%
figure;
plot_mask(mask_after_imclose, hop, nbins, fs);
title('Smooth mask- after imclose');
%%
figure;
plot_mask(mask, hop, nbins, fs);
title('Smooth and final mask - after impoen');
%%
clc; clear; close all;
%%
t_lim = [0.3, 0.5];
f_lim =[0.1, 0.2];
nbins=128;
hop =2;
sig_len=1024;
fs=1;
mask = generate_rectangular_mask(nbins, hop, sig_len, t_lim, f_lim);
figure; plot_mask(mask, hop, nbins, fs)
title(['mask ',num2str(sig_len)])
clc; clear; close all
%%
% This script tests the operators of the DGT
%%
win_type='gauss';
sig_len=16384;
fs=8000;
approx_win_len=256;
hop=approx_win_len/4;
nbins=approx_win_len*4;
signal_params= generate_signal_parameters(fs, sig_len);
dgt_params = generate_dgt_parameters(win_type, approx_win_len, hop, nbins, sig_len);
[dgt, idgt] = get_stft_operators(dgt_params, signal_params);
s_2 = randn(signal_params.sig_len,1);
X = dgt(s_2);
xrec = idgt(X);
norm(s_2-xrec)
figure('name','spectrogram'); imagesc(abs(X))
\ No newline at end of file
clc; clear; close all;
%%
%This script is used to test the wave_read function.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = load('signal_lists.mat');
ind_wideband = 1;
ind_localized = 2;
wideband_file = [data.wide_band_sources_files(ind_wideband).folder, filesep,...
data.wide_band_sources_files(ind_wideband).name];
localized_file = [data.localized_sources_files(ind_localized).folder, filesep, ...
data.localized_sources_files(ind_localized).name];
deb=0;
sig_len = 16384;
fs=8000;
signal_params = generate_signal_parameters(fs, sig_len);
x= wave_read(wideband_file, fs, sig_len,deb);
figure; sgram(x,'dynrange',90)
\ No newline at end of file
Supports Markdown
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