├── .gitignore ├── README.md ├── Yousefian ├── COH_RealImag.m └── ReIm_Coherence.m ├── applyProcess_real.m ├── applyProcess_sim.m ├── applyProcess_simSNR.m ├── getweights.m ├── lib ├── +file │ └── find_pcm.m ├── +sim │ ├── ANF-Generator-master │ │ ├── LICENSE │ │ ├── README.md │ │ ├── babble_8kHz.wav │ │ ├── biorwin.m │ │ ├── cohere_mod.m │ │ ├── gen_noisefield.m │ │ ├── istft.m │ │ ├── mix_signals.m │ │ ├── stft.m │ │ └── 音轨-2.wav │ ├── RIR_generator_URA.m │ ├── gen_babble_speech.m │ ├── generate_signal.m │ ├── noise_gen_URA.m │ └── signal_simulation.m ├── +util │ ├── fig.m │ ├── play.m │ ├── plot.m │ └── visual.m ├── GenNoiseMSC.m ├── GenNoiseMSC_shift.m ├── istft.m ├── mycohere.m ├── patternURA.m ├── spectral_subtraction.m ├── stft.m ├── stft_test.m ├── update_CSD.m ├── update_MSC.m └── update_PSD.m ├── plotSNR.m ├── process.m ├── process_SNR.m └── wav ├── COH_CT_90.wav ├── STEREO_0024.pcm ├── S_01_01.wav ├── S_01_01_rec.wav ├── S_72_09.wav ├── Unp_Front_CT_90.wav ├── Unp_Rear_CT_90.wav └── xmos ├── rec ├── readme.txt ├── 音轨-2.wav ├── 音轨-3.wav ├── 音轨-4.wav └── 音轨-5.wav └── rec96 ├── readme.txt ├── 音轨-2.wav ├── 音轨-3.wav ├── 音轨-4.wav └── 音轨-5.wav /.gitignore: -------------------------------------------------------------------------------- 1 | ##ignore this file## 2 | 3 | EventDetector/bin/EventDetector 4 | 5 | EventDetector/Makefile 6 | 7 | EventDetector/CMakeFiles/ 8 | 9 | cmake_install.cmake 10 | 11 | CMakeCache.txt 12 | 13 | *.asv 14 | 15 | *.pk 16 | 17 | *.d 18 | 19 | # Object files 20 | *.o 21 | *.ko 22 | *.obj 23 | *.elf 24 | 25 | # Linker output 26 | *.ilk 27 | *.map 28 | *.exp 29 | 30 | # Precompiled Headers 31 | *.gch 32 | *.pch 33 | 34 | # Libraries 35 | *.lib 36 | *.a 37 | *.la 38 | *.lo 39 | 40 | # Shared objects (inc. Windows DLLs) 41 | *.dll 42 | *.so 43 | *.so.* 44 | *.dylib 45 | 46 | # Executables 47 | *.exe 48 | *.out 49 | *.app 50 | *.i*86 51 | *.x86_64 52 | *.hex 53 | 54 | # Debug files 55 | *.dSYM/ 56 | *.su 57 | *.idb 58 | *.pdb 59 | 60 | # Kernel Module Compile Results 61 | *.mod* 62 | *.cmd 63 | .tmp_versions/ 64 | modules.order 65 | Module.symvers 66 | Mkfile.old 67 | dkms.conf 68 | 69 | output/ 70 | #*real* 71 | batchtest/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **implement some coherence-based dual-mic noise reduction algorithm** 2 | 3 | 4 | refer to 5 | 6 | - [1] N. Yousefian and P. C. Loizou, "A Dual-Microphone Speech Enhancement Algorithm 7 | Based on the Coherence Function," in IEEE Transactions on Audio, Speech, and 8 | Language Processing, vol. 20, no. 2, pp. 599-609, Feb. 2012. 9 | 10 | - [2] N. Yousefian and P. C. Loizou, “A dual-microphone algorithm that can cope with competing-talker scenarios,” IEEE Trans. Audio, Speech,Lng. Process., vol. 21, no. 1, pp. 145–155, 2013. 11 | 12 | - [3] Yousefian, N., Hansen, J. H. L., & Loizou, P. C. (2015). A Hybrid Coherence Model for Noise Reduction in Reverberant Environments. IEEE Signal Processing Letters, 22(3), 279–282. doi:10.1109/lsp.2014.2352352  13 | 14 | - [4] Ji, Y., Byun, J., Park, Y. (2017) Coherence-Based Dual-Channel Noise Reduction 15 | Algorithm in a Complex Noisy Environment. Proc. Interspeech 2017 16 | 17 | 18 | -------------------------------------------------------------------------------- /Yousefian/COH_RealImag.m: -------------------------------------------------------------------------------- 1 | function [enhanced_ouput]=COH_RealImag(x1,x2,fs,output_fn) 2 | % x1 , x2 : Input signals at two channels 3 | % fs : Sampling Frequency 4 | % output_path: path to write enhanced file 5 | % Nima Yousefian , Sep 2012 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | %Reference: Nima Yousefian, Philipos C. Loizou: A Dual-Microphone 8 | %Speech Enhancement Algorithm Based on the Coherence Function. IEEE 9 | %Transactions on Audio, Speech & Language Processing 20(2): 599-609 (2012) 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | disp('Run Speech Enhacement COH----'); 12 | frameLength=floor(15*fs/1000); 13 | if (frameLength/2 ~= floor(frameLength/2)) 14 | frameLength=frameLength+1; 15 | end 16 | 17 | frameShift=floor(frameLength* 0.5); 18 | window=hanning(frameLength); 19 | FFT_LEN=2^nextpow2(frameLength); 20 | 21 | lambda_x=0.68; %Forgetting factor for smoothing power spectrum 22 | epsilon=10^-12; 23 | 24 | lenS=min(length(x1),length(x2)); 25 | nFrame=0; 26 | iniFrameSample=1; 27 | endFrameSample=iniFrameSample+frameLength-1; 28 | enhanced_ouput=zeros(lenS,1); 29 | %Defining bands 30 | band1=floor(1000*FFT_LEN/fs); %0 -> 1 KHz 31 | %Defining exponents of coherence function 32 | P=zeros(FFT_LEN/2,1); 33 | P(1:band1)=16; 34 | P(band1+1:FFT_LEN/2)=2; 35 | 36 | %Defining threshholds for imaganary parts to consider negative (noise) 37 | limNeg=zeros(FFT_LEN/2,1); 38 | limNeg(1:band1)=-0.1; 39 | limNeg(band1+1:FFT_LEN/2)=-0.3; 40 | %Constant value of filter when imag part is negative 41 | negImag_ConsFilter=0.05; 42 | 43 | while endFrameSample Endfire, 90 -> Broadside) 35 | 36 | %setting freq. bins between 0 and pi/2 37 | f_bin=0:1/FFT_LEN:0.5; 38 | f_bin(1)=[]; 39 | omega=2 * pi * f_bin; 40 | omega_tau=omega'*tau.*cos(Target_DOA); 41 | pri_min=10^(-40/10); 42 | 43 | while endFrameSample Alpha 77 | T=1-reCOH.*cos(omega_tau)-imCOH.*sin(omega_tau); 78 | 79 | sin_alpha=(-B.*C + A .* T)./ (A.^2 + B.^2); 80 | SNR_Hat= (sin_alpha - imCOH) ./ (A) ; 81 | SNR_Hat=max(SNR_Hat,pri_min); 82 | 83 | %Wiener gain 84 | W_cur = SNR_Hat(1:FFT_LEN/2) ./ (SNR_Hat(1:FFT_LEN/2) +1); 85 | G= sqrt(W_cur); 86 | H=abs([G ;flipud(G)]); %Fullband final filter 87 | 88 | %IFFT and OLA 89 | enhSpeech_Frame_tmp=real(ifft( H .* X1,FFT_LEN)); 90 | enhSpeech_Frame=enhSpeech_Frame_tmp(1:frameLength); 91 | enhanced_ouput(iniFrameSample:endFrameSample)=enhSpeech_Frame + enhanced_ouput(iniFrameSample:endFrameSample); 92 | 93 | %Update frame boundaries 94 | iniFrameSample=iniFrameSample+frameShift; 95 | endFrameSample=endFrameSample+frameShift; 96 | end 97 | disp('Processing ... 100% Done'); 98 | % wavwrite(enhanced_ouput,fs,16,output_fn); -------------------------------------------------------------------------------- /applyProcess_real.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % endfire 4 | % refer to "A Dual-Microphone Speech Enhancement Algorithm 5 | % Based on the Coherence Function" 6 | % 7 | % broadside 8 | % refer to "A coherence-based noise reduction algorithm for binaural 9 | % hearing aids" 10 | % 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | % close all 14 | % clear all; 15 | %addpath(genpath('lib')); 16 | c = 340; % speed of sound 17 | 18 | %% 19 | %% load recorded office noise audio 20 | 21 | fs = 16000; 22 | 23 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 24 | M = size(x,2); 25 | %% 26 | frameLength = 256; 27 | overlap = 128; 28 | inc = frameLength - overlap; 29 | N_FFT = 256; 30 | % test xmos 4-mic circular array recordings 31 | x = loadwav('wav/xmos/rec/'); 32 | d = 0.064; 33 | switch 1 34 | case 1 35 | x = x(:,[1,3]); % extract speaker-1 36 | disp('speaker-1 is in front of mic1') 37 | case 2 38 | x = x(:,[4,2]); % extract speaker-2 39 | disp('speaker-2 is in front of mic4') 40 | otherwise 41 | disp('other value') 42 | end 43 | 44 | x1 = x; 45 | 46 | %% process 47 | 48 | [ y,Fvv2,SNR] = process(x1,d); 49 | 50 | %% evaluate 51 | speech = sig.speech; 52 | % [pesq_mos]= pesq_vec(speech, out,fs) 53 | %rmpath(genpath('lib')); 54 | visual( x(:,1),y ); 55 | % util.fig(out, fs); 56 | 57 | 58 | -------------------------------------------------------------------------------- /applyProcess_sim.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % endfire 4 | % refer to "A Dual-Microphone Speech Enhancement Algorithm 5 | % Based on the Coherence Function" 6 | % 7 | % broadside 8 | % refer to "A coherence-based noise reduction algorithm for binaural 9 | % hearing aids" 10 | % 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | % close all 14 | % clear all; 15 | addpath(genpath('lib')); 16 | addpath(genpath('E:\work\matlab\ehabets\ANF-Generator-master')); 17 | c = 340; % speed of sound 18 | 19 | %% 20 | %% load recorded office noise audio 21 | 22 | fs = 16000; 23 | 24 | angle = [0,0]/180*pi; 25 | % array spacing 26 | d = 0.025; 27 | r = d/2; 28 | 29 | switch 1 30 | case 1 31 | slice = [1,3]; % extract speaker-1 32 | disp('speaker-1 is in front of mic1') 33 | case 2 34 | slice = [2,4]; % extract speaker-2 35 | disp('speaker-2 is in front of mic2') 36 | otherwise 37 | disp('other value') 38 | end 39 | 40 | [ sig ] = sim.signal_simulation( r,slice ); 41 | rmpath(genpath('E:\work\matlab\ehabets\ANF-Generator-master')); 42 | x = sig.x; 43 | 44 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45 | M = size(x,2); 46 | %% 47 | frameLength = 256; 48 | overlap = 128; 49 | inc = frameLength - overlap; 50 | N_FFT = 256; 51 | 52 | x1 = x; 53 | 54 | %% process 55 | 56 | [ y,Fvv2,SNR] = process(x1,d,7); 57 | 58 | %% evaluate 59 | speech = sig.speech; 60 | % [pesq_mos]= pesq_vec(speech, out,fs) 61 | rmpath(genpath('lib')); 62 | stoi(sig.clean_i(:,1),x(:,1),fs) %% STOI for noisy speech 63 | stoi(sig.clean_i(1:length(y),1),y,fs) %% STOI for processed speech 64 | visual( x(:,1),y ); 65 | % util.fig(out, fs); 66 | 67 | 68 | -------------------------------------------------------------------------------- /applyProcess_simSNR.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % endfire 4 | % refer to "A Dual-Microphone Speech Enhancement Algorithm 5 | % Based on the Coherence Function" 6 | % 7 | % broadside 8 | % refer to "A coherence-based noise reduction algorithm for binaural 9 | % hearing aids" 10 | % 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | close all 14 | clear all; 15 | addpath(genpath('lib')); 16 | 17 | % array spacing 18 | d = 0.0213; 19 | r = d/2; 20 | 21 | slice = [1,3]; 22 | [ sig ] = sim.signal_simulation( r,slice ); 23 | 24 | ang = [0,0]*pi/180; 25 | 26 | % SNR = snr(clean_s(:,1),clean_i(:,1)) 27 | 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 29 | M = size(sig.x,2); 30 | %% process 31 | frameLength = 256; 32 | overlap = 128; 33 | inc = frameLength - overlap; 34 | N_FFT = 256; 35 | 36 | fs = 16000; 37 | c = 340; 38 | f = 0:fs/256:fs/2; 39 | 40 | N_FFT = 256; 41 | k = 0:1:N_FFT/2; 42 | omega = 2*pi*k/N_FFT; 43 | 44 | tau = fs*d/c; 45 | Fx1x2 = exp(1j*omega*tau); 46 | 47 | [ out,Fvv2,SNR,SNR_predict,P_s,P_i,P_x,Fvv_all_est] = process_SNR(sig.clean_s,sig.clean_i,d); 48 | %% compare predict SNR with true SNR 49 | figure, 50 | subplot(2,1,1),plotSNR( SNR ),title('true SNR'), 51 | subplot(2,1,2),plotSNR( SNR_predict ),title('predict SNR') 52 | frame = 280; 53 | figure,plot(10*log10(SNR(frame,:))) 54 | hold on ,plot(10*log10(SNR_predict(frame,:))),legend(['true SNR at frame ',int2str(frame)],... 55 | ['predict SNR at frame ',int2str(frame)]) 56 | 57 | Fvv_s_n = squeeze(P_s.Fvv_all(frame,1,2,:)); 58 | figure, 59 | plot(real(Fvv_s_n)) 60 | hold on,plot(cos(omega*tau*cos(ang(1)))),title('real part of coherence'), 61 | legend('estimated','theoretical'); 62 | 63 | 64 | %% compare predict coherence with true coherence 65 | k = 16; 66 | Fvv_s_k = squeeze(P_s.Fvv_all(:,1,2,k)); 67 | Fvv_i_k = squeeze(P_i.Fvv_all(:,1,2,k)); 68 | Fvv_x_k = squeeze(P_x.Fvv_all(:,1,2,k)); 69 | Fvv_all_est_k = squeeze(Fvv_all_est(:,1,2,k)); 70 | figure, 71 | subplot(2,1,1),plot(real(Fvv_x_k)),hold on,plot(real(Fvv_all_est_k)) % magnitude 72 | legend(['coherence of noisy signal at ',int2str(fix(k*fs/N_FFT)),'Hz'],... 73 | ['coherence of model at ',int2str(fix(k*fs/N_FFT)),'Hz']),title('magnitude'); 74 | subplot(2,1,2),plot(angle(Fvv_x_k)),hold on,plot(angle(Fvv_all_est_k)),title('phase'); % phase 75 | 76 | %% estimate coherence affected by signal or noise with SNR 77 | Fvv_s_n = squeeze(P_s.Fvv_all(frame,1,2,:)); 78 | Fvv_i_n = squeeze(P_i.Fvv_all(frame,1,2,:)); 79 | Fvv_x_n = squeeze(P_x.Fvv_all(frame,1,2,:)); 80 | figure,plot(real(Fvv_s_n)),hold on,plot(real(Fvv_i_n)),hold on,plot(real(Fvv_x_n)); 81 | hold on,plot(10*log10(SNR(frame,:))/max(abs(10*log10(SNR(frame,:))))) 82 | legend(['coherence of source at frame ',int2str(frame)],... 83 | ['coherence of noise at frame ',int2str(frame)],... 84 | ['coherence of noisy at frame ',int2str(frame)],... 85 | ['normalized true SNR at frame ',int2str(frame)]) 86 | figure,plot(10*log10(SNR(frame,:)));title(['true SNR(dB) at frame ',int2str(frame)]) 87 | 88 | speech = sig.speech; 89 | % [pesq_mos]= pesq_vec(speech, out,fs) 90 | % visual( x(:,1),out ); 91 | rmpath(genpath('lib')); 92 | 93 | -------------------------------------------------------------------------------- /getweights.m: -------------------------------------------------------------------------------- 1 | function [G, SNR] = getweights(Fvv, k, d, Gmin, method) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % get dual-mic coherence-based weight 5 | % example Usage: 6 | % Y = getweights(Fvv,16,0.032,0.1) 7 | % 8 | % Inputs: 9 | % Fvv coherence function at k frequency bin 10 | % k frequency bin 11 | % d dual-min distance 12 | % Gmin gain floor 13 | % 14 | % 15 | % Outputs: 16 | % G filter gain 17 | % SNR estimate SNR 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | 20 | if ~exist('Gmin', 'var') 21 | Gmin = 0.1; 22 | end 23 | 24 | if ~exist('method', 'var') 25 | method = 2; 26 | end 27 | 28 | fs = 16000; 29 | N_FFT = (size(Fvv,3)-1)*2; 30 | c = 340; 31 | dij = d; 32 | 33 | Fy_real = real(Fvv(1, 2, k)); 34 | Fy_imag = imag(Fvv(1, 2, k)); 35 | 36 | switch method 37 | case 1 38 | % endfire 39 | % refer to 40 | % "A Dual-Microphone Speech Enhancement Algorithm 41 | % Based on the Coherence Function" 42 | alpha_low = 16; 43 | alpha_hi = 2; 44 | beta_low = -0.1; 45 | beta_hi = -0.3; 46 | mu = 0.05; 47 | gamma = 0.6; 48 | 49 | SNR_est = (1 - (real(Fvv(1, 2, k)))^2 - imag(Fvv(1, 2, k))^2) / ... 50 | ((1 - real(Fvv(1, 2, k)))^2 + imag(Fvv(1, 2, k))^2); 51 | 52 | if SNR_est < 0.01 53 | L = 1; 54 | elseif SNR_est > 100 55 | L = 512; 56 | else 57 | L = 2^(SNR_est / 5 + 5); 58 | end 59 | 60 | G = 1 - abs(real(Fvv(1, 2, k)))^L; 61 | 62 | if (k <= 16) 63 | G1 = 1 - abs(real(Fvv(1, 2, k)))^alpha_low; 64 | Q = beta_low; 65 | else 66 | G1 = 1 - abs(real(Fvv(1, 2, k)))^alpha_hi; 67 | Q = beta_hi; 68 | end 69 | 70 | if (imag(Fvv(1, 2, k)) < Q) 71 | G2 = mu; 72 | else 73 | G2 = 1; 74 | end 75 | 76 | G = G1 * G2; % endfire 77 | case 2 78 | % refer to 79 | % [1] "A Dual-Microphone Algorithm That Can 80 | % Cope With Competing-Talker Scenarios" 81 | % endfire ,coherent 82 | 83 | %theta = 0 * pi / 180; % 90,interference broadside 84 | ata = 0 * pi / 180; % 0,target endfire 85 | omega = 2 * pi * (k - 1) / N_FFT; 86 | tao = fs * d / c; 87 | omega_ = omega * tao; 88 | beta = omega_ * cos(ata); 89 | %alpha = omega_ * cos(theta); 90 | 91 | A = Fy_imag - sin(omega_); 92 | B = cos(omega_) - Fy_real; 93 | C = Fy_real * sin(omega_) - Fy_imag * cos(omega_); % eq.13 94 | 95 | T = 1 - Fy_real * cos(omega_) - Fy_imag * sin(omega_); % eq.18 96 | 97 | sin_alpha = (-1 * B * C + A * T) / ... 98 | (A^2 + B^2); % eq.17/18 99 | SNR = (sin_alpha - Fy_imag) / ... 100 | (Fy_imag - sin(beta)); % eq.11 in [1] 101 | 102 | % square-root wiener filter 103 | G = sqrt(SNR / ... 104 | (SNR + 1)); 105 | 106 | case 5 107 | % refer to 108 | % [1] "A coherence-based noise reduction algorithm for binaural 109 | % hearing aids" 110 | % broadside ,coherent 111 | % [2] "A Joint Speech Enhancement Algorithm Based on the 112 | % Tri-microphone" 113 | 114 | sin_alpha = (2*(1-Fy_real)*Fy_imag) / ... 115 | ((1-Fy_real)^2+Fy_imag^2); % eq.19 in [1] 116 | G = (1-Fy_real^2-Fy_imag^2)/... 117 | (2*(1-Fy_real)); % eq.20 in [1] 118 | SNR = (1-Fy_real^2-Fy_imag^2)/... 119 | ((1-Fy_real)^2+Fy_imag^2); % eq.23 in [1] 120 | % is 121 | % equal 122 | SNR = (sin_alpha - Fy_imag) / ... % to 123 | (Fy_imag); % eq.7 in [2] 124 | G = sqrt(SNR / ... 125 | (SNR + 1)); 126 | case 3 127 | % 128 | % refer to 129 | % "Hybrid Coherence Model for Noise Reduction in Reverberant 130 | % Environments" 131 | % 132 | k_optimal = 1; 133 | 134 | 135 | abs_Fvv2 = sqrt(Fy_real^2 + Fy_imag^2); 136 | Fn = sin(2 * pi * k * fs * dij * k_optimal / c / N_FFT) ./ (2 * pi * k * fs * dij * k_optimal / c / N_FFT); 137 | % Fn = sinc(2*pi*k*fs*d/(N_FFT*c)); 138 | 139 | DDR = (abs(Fn)^2 - abs_Fvv2^2) / ... 140 | (abs_Fvv2^2 - 1); 141 | K = DDR / (DDR + 1); 142 | %theta = 0 * pi / 180; % 90,interference broadside 143 | ata = 0 * pi / 180; % 0,target endfire 144 | % omega = 2*pi*k/N_FFT; 145 | omega = 2 * (k - 1) / N_FFT; 146 | tao = fs * d / c; 147 | omega_ = omega * tao; 148 | beta = pi * omega_ * cos(ata); 149 | %alpha = omega_ * cos(theta); 150 | constant = 2 * pi * k * fs * d / ((N_FFT * c)); 151 | 152 | % if we set K = 1,then this method is same as method2 153 | A = K * (Fy_imag - sin(beta)); 154 | B = (1 - K) * sinc(omega_) + K * cos(beta) - Fy_real; 155 | C = Fy_real * sin(beta) - Fy_imag * K * cos(beta) - (1 - K) * sinc(omega_) * sin(beta); 156 | T = K - Fy_real * cos(beta) - K * Fy_imag * sin(beta) + (1 - K) * sinc(omega_) * cos(beta); 157 | 158 | sin_alpha = (-1 * B * C + A * T) / ... 159 | (A^2 + B^2); % eq.14 160 | SNR = (sin_alpha - Fy_imag) / ... 161 | (Fy_imag - sin(beta)); % eq.10 162 | 163 | if (SNR <- 0.99 || isnan(SNR)) 164 | SNR = -0.99; 165 | end 166 | G = SNR / ... 167 | SNR + 1; 168 | G = G^2; 169 | 170 | % G = sqrt(SNR / ... 171 | % (SNR + 1)); 172 | case 4 173 | % refer to "Coherence-based dual-channel noise reduction algorithm in a complex noisy 174 | % environment" method_1 175 | % endfire ,coherent+diffuse 176 | k_optimal = 1; 177 | 178 | Fy_real = real(Fvv(1, 2, k)); 179 | Fy_imag = imag(Fvv(1, 2, k)); 180 | Fn = sin(2 * pi * k * fs * dij * k_optimal / c / N_FFT) ./ (2 * pi * k * fs * dij * k_optimal / c / N_FFT); 181 | % Fn = sinc(2*pi*k*fs*d/(N_FFT*c)); 182 | 183 | 184 | abs_Fvv2 = sqrt(Fy_real^2 + Fy_imag^2); 185 | 186 | 187 | DDR = (abs(Fn)^2 - abs_Fvv2^2) / ... 188 | (abs_Fvv2^2 - 1+1e-6); 189 | % DDR = max(0,DDR); 190 | K = DDR / (DDR + 1); 191 | % K = 1; 192 | theta_s = 90 * pi / 180; % 90,target,endfire 193 | %theta_i = 0 * pi / 180; % 0,interference ,broadside 194 | constant = 2 * pi * (k - 1) * fs * d / ((N_FFT * c)); 195 | sin_alpha = sin(constant * sin(theta_s)); 196 | cos_alpha = cos(constant * sin(theta_s)); 197 | A = sin_alpha * K - Fy_imag; 198 | B = cos_alpha * K - Fy_real + Fn * (1 - K); 199 | C = (Fy_real - Fn * (1 - K)) * sin_alpha - Fy_imag * cos_alpha; 200 | T = K - cos_alpha * (Fy_real - Fn * (1 - K)) - Fy_imag * sin_alpha; 201 | sin_beta = (-1 * B * C - A * T) / ... 202 | (A^2 + B^2); 203 | G = ((Fy_imag - sin_beta * K) / ... 204 | (sin_alpha - sin_beta)); 205 | SNR = G / (1 - G); 206 | % G = G*K; 207 | case 6 208 | % refer to "Coherence-based dual-channel noise reduction algorithm in a complex noisy 209 | % environment" method_3 210 | % endfire ,coherent+diffuse 211 | k_optimal = 1; 212 | SPECTRAL_FLOOR = 0.4; 213 | Fvv_UPPER = 0.98; 214 | Fy_real = real(Fvv(1, 2, k)); 215 | Fy_imag = imag(Fvv(1, 2, k)); 216 | Fn = sin(2 * pi * k * fs * dij * k_optimal / c / N_FFT) ./ (2 * pi * k * fs * dij * k_optimal / c / N_FFT); 217 | % Fn = sinc(2*pi*k*fs*d/(N_FFT*c)); 218 | 219 | if (Fy_real > Fvv_UPPER) 220 | Fy_real = Fvv_UPPER; 221 | end 222 | 223 | abs_Fvv2 = sqrt(Fy_real^2 + Fy_imag^2); 224 | 225 | if (abs_Fvv2 > Fvv_UPPER) 226 | abs_Fvv2 = Fvv_UPPER; 227 | end 228 | 229 | 230 | DDR = (abs(Fn)^2 - abs_Fvv2^2) / ... 231 | (abs_Fvv2^2 - 1); 232 | K = DDR / (DDR + 1); 233 | % K = 1; 234 | theta_s = 90 * pi / 180; % 90,target,endfire 235 | %theta_i = 0 * pi / 180; % interference ,broadside 236 | constant = 2 * pi * (k - 1) * fs * d / ((N_FFT * c)); 237 | sin_alpha = sin(constant * sin(theta_s)); 238 | cos_alpha = cos(constant * sin(theta_s)); 239 | 240 | A = sin_alpha * K - Fy_imag; 241 | B = cos_alpha * K - Fy_real + Fn * (1 - K); 242 | C = (Fy_real - Fn * (1 - K)) * sin_alpha - Fy_imag * cos_alpha; 243 | T = K - cos_alpha * (Fy_real - Fn * (1 - K)) - Fy_imag * sin_alpha; 244 | sin_beta = (-1 * B * C - A * T) / ... 245 | (A^2 + B^2); % eq.21 246 | cos_beta = (A*C-B*T)/(A^2+B^2); % eq.22 247 | 248 | A_ = cos_alpha - cos_beta; 249 | B_ = cos_beta + Fn*(1-K); 250 | C_ = sin_alpha - sin_beta; 251 | D_ = sin_beta*K; % eq.16 252 | 253 | if(abs(Fy_imag-sin_alpha) 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/README.md: -------------------------------------------------------------------------------- 1 | # Generating Nonstationary Multisensor Signals under a Spatial Coherence Constraint 2 | 3 | Noise fields encountered in real-life scenarios can often be approximated as spherical or cylindrical noise fields. The characteristics of the noise field can be described by a spatial coherence function. For simulation purposes, researchers in the signal processing community often require sensor signals that exhibit a specific spatial coherence function. In addition, they often require a specific type of noise such as temporally correlated noise, babble speech that comprises a mixture of mutually independent speech fragments, or factory noise. Existing algorithms are unable to generate sensor signals such as babble speech and factory noise observed in an arbitrary noise field. 4 | 5 | In [1] an efficient algorithm is proposed that generates multisensor signals under a predefined spatial coherence constraint. The benefit of the developed algorithm is twofold. Firstly, there are no restrictions on the spatial coherence function. Secondly, to generate M sensor signals the algorithm requires only M mutually independent noise signals. The performance evaluation shows that the developed algorithm is able to generate a more accurate spatial coherence between the generated sensor signals compared to the so-called image method that is frequently used in the acoustic signal processing community. 6 | 7 | 1. E.A.P. Habets, I. Cohen and S. Gannot 8 | Generating nonstationary multisensor signals under a spatial coherence constraint, Journal of the Acoustical Society of America, Vol. 124, Issue 5, pp. 2911-2917, Nov. 2008. 9 | -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/babble_8kHz.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/+sim/ANF-Generator-master/babble_8kHz.wav -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/biorwin.m: -------------------------------------------------------------------------------- 1 | function win=biorwin(wins,dM,dN); 2 | % biorbin : Find Biorthogonal analysis Window for STFT 3 | % ***************************************************************@ 4 | % Inputs: 5 | % wins, synthesis window; 6 | % dM, sampling step in Time; 7 | % dN, sampling step in Frequency; 8 | % Output: 9 | % win, analysis window; 10 | % Usage: 11 | % win=biorwin(wins,dM,dN); 12 | % Defaults: 13 | % noverlap=length(wins)/2; 14 | 15 | % Copyright (c) 2000. Dr Israel Cohen. 16 | % All rights reserved. Created 5/12/00. 17 | % ***************************************************************@ 18 | 19 | wins=wins(:); 20 | L=length(wins); 21 | N=L/dN; 22 | win=zeros(L,1); 23 | mu=zeros(2*dN-1,1); 24 | mu(1)=1; 25 | %mu(1)=1/N; 26 | for k=1:dM 27 | % H=zeros(2*dN-1,ceil(L/dM)); 28 | % for q=0:2*dN-2 29 | % h=shiftcir(wins,q*N); 30 | % H(q+1,:)=h(k:dM:L)'; 31 | % end 32 | H = wins(k:dM:L); 33 | win(k:dM:L)=pinv(H)*mu; 34 | end 35 | %win=win/max(win); 36 | 37 | -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/cohere_mod.m: -------------------------------------------------------------------------------- 1 | function [Cxy, f] = cohere_mod(varargin) 2 | %COHERE Coherence function estimate. 3 | % Cxy = COHERE(X,Y,NFFT,Fs,WINDOW) estimates the coherence of X and Y 4 | % using Welch's averaged periodogram method. Coherence is a function 5 | % of frequency with values between 0 and 1 that indicate how well the 6 | % input X corresponds to the output Y at each frequency. X and Y are 7 | % divided into overlapping sections, each of which is detrended, then 8 | % windowed by the WINDOW parameter, then zero-padded to length NFFT. 9 | % The magnitude squared of the length NFFT DFTs of the sections of X and 10 | % the sections of Y are averaged to form Pxx and Pyy, the Power Spectral 11 | % Densities of X and Y respectively. The products of the length NFFT DFTs 12 | % of the sections of X and Y are averaged to form Pxy, the Cross Spectral 13 | % Density of X and Y. The coherence Cxy is given by 14 | % Cxy = (abs(Pxy).^2)./(Pxx.*Pyy) 15 | % Cxy has length NFFT/2+1 for NFFT even, (NFFT+1)/2 for NFFT odd, or NFFT 16 | % if X or Y is complex. If you specify a scalar for WINDOW, a Hanning 17 | % window of that length is used. Fs is the sampling frequency which does 18 | % not effect the cross spectrum estimate but is used for scaling of plots. 19 | % 20 | % [Cxy,F] = COHERE(X,Y,NFFT,Fs,WINDOW,NOVERLAP) returns a vector of freq- 21 | % uencies the same size as Cxy at which the coherence is computed, and 22 | % overlaps the sections of X and Y by NOVERLAP samples. 23 | % 24 | % COHERE(X,Y,...,DFLAG), where DFLAG can be 'linear', 'mean' or 'none', 25 | % specifies a detrending mode for the prewindowed sections of X and Y. 26 | % DFLAG can take the place of any parameter in the parameter list 27 | % (besides X and Y) as long as it is last, e.g. COHERE(X,Y,'mean'); 28 | % 29 | % COHERE with no output arguments plots the coherence in the current 30 | % figure window. 31 | % 32 | % The default values for the parameters are NFFT = 256 (or LENGTH(X), 33 | % whichever is smaller), NOVERLAP = 0, WINDOW = HANNING(NFFT), Fs = 2, 34 | % P = .95, and DFLAG = 'none'. You can obtain a default parameter by 35 | % leaving it off or inserting an empty matrix [], e.g. 36 | % COHERE(X,Y,[],10000). 37 | % 38 | % See also PSD, CSD, TFE. 39 | % ETFE, SPA, and ARX in the Identification Toolbox. 40 | 41 | % Author(s): T. Krauss, 3-31-93 42 | % Copyright (c) 1988-98 by The MathWorks, Inc. 43 | % $Revision: 1.1 $ $Date: 1998/06/03 14:42:19 $ 44 | 45 | narginchk(2,7); 46 | x = varargin{1}; 47 | y = varargin{2}; 48 | %[msg,nfft,Fs,window,noverlap,p,dflag]=psdchk(varargin(3:end),x,y); 49 | %error(msg) 50 | nfft = varargin{3}; 51 | Fs = varargin{4}; 52 | window = varargin{5}; 53 | noverlap = varargin{6}; 54 | %p = .95; 55 | dflag = 'none'; 56 | 57 | % compute PSD and CSD 58 | window = window(:); 59 | n = length(x); % Number of data points 60 | nwind = length(window); % length of window 61 | if n < nwind % zero-pad x , y if length is less than the window length 62 | x(nwind)=0; 63 | y(nwind)=0; 64 | n=nwind; 65 | end 66 | x = x(:); % Make sure x is a column vector 67 | y = y(:); % Make sure y is a column vector 68 | k = fix((n-noverlap)/(nwind-noverlap)); % Number of windows 69 | % (k = fix(n/nwind) for noverlap=0) 70 | index = 1:nwind; 71 | 72 | Pxx = zeros(nfft,1); Pxx2 = zeros(nfft,1); 73 | Pyy = zeros(nfft,1); Pyy2 = zeros(nfft,1); 74 | Pxy = zeros(nfft,1); Pxy2 = zeros(nfft,1); 75 | for i=1:k 76 | if strcmp(dflag,'none') 77 | xw = window.*x(index); 78 | yw = window.*y(index); 79 | elseif strcmp(dflag,'linear') 80 | xw = window.*detrend(x(index)); 81 | yw = window.*detrend(y(index)); 82 | else 83 | xw = window.*detrend(x(index),0); 84 | yw = window.*detrend(y(index),0); 85 | end 86 | index = index + (nwind - noverlap); 87 | Xx = fft(xw,nfft); 88 | Yy = fft(yw,nfft); 89 | Xx2 = abs(Xx).^2; 90 | Yy2 = abs(Yy).^2; 91 | Xy2 = Yy.*conj(Xx); 92 | Pxx = Pxx + Xx2; 93 | Pxx2 = Pxx2 + abs(Xx2).^2; 94 | Pyy = Pyy + Yy2; 95 | Pyy2 = Pyy2 + abs(Yy2).^2; 96 | Pxy = Pxy + Xy2; 97 | Pxy2 = Pxy2 + Xy2.*conj(Xy2); 98 | end 99 | 100 | % Select first half 101 | if ~any(any(imag([x y])~=0)) % if x and y are not complex 102 | if rem(nfft,2) % nfft odd 103 | select = 1:(nfft+1)/2; 104 | else 105 | select = 1:nfft/2+1; % include DC AND Nyquist 106 | end 107 | Pxx = Pxx(select); 108 | %Pxx2 = Pxx2(select); 109 | Pyy = Pyy(select); 110 | %Pyy2 = Pyy2(select); 111 | Pxy = Pxy(select); 112 | %Pxy2 = Pxy2(select); 113 | else 114 | select = 1:nfft; 115 | end 116 | %Coh = (abs(Pxy).^2)./(Pxx.*Pyy); % squared coherence function estimate 117 | Coh = Pxy./sqrt(Pxx.*Pyy); % coherence function estimate 118 | freq_vector = (select - 1)'*Fs/nfft; 119 | 120 | % set up output parameters 121 | if (nargout == 2) 122 | Cxy = Coh.'; 123 | f = freq_vector; 124 | elseif (nargout == 1) 125 | Cxy = Coh; 126 | elseif (nargout == 0) % do a plot 127 | newplot; 128 | plot(freq_vector,Coh), grid on 129 | xlabel('Frequency'), ylabel('Coherence Function Estimate'); 130 | end -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/gen_noisefield.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------------------------------- 2 | % 3 | % Example that generates an isotopic noisy field received by a uniform 4 | % linear array of sensors. 5 | % 6 | % Author : E.A.P. Habets 7 | % Date : 29-06-2017 8 | % 9 | % Related paper : E.A.P. Habets, I. Cohen and S. Gannot, 'Generating 10 | % nonstationary multisensor signals under a spatial 11 | % coherence constraint', Journal of the Acoustical Society 12 | % of America, Vol. 124, Issue 5, pp. 2911-2917, Nov. 2008. 13 | % 14 | % Copyright (C) 2009-2017 E.A.P. Habets 15 | % 16 | % This program is free software; you can redistribute it and/or modify 17 | % it under the terms of the GNU General Public License as published by 18 | % the Free Software Foundation; either version 2 of the License, or 19 | % (at your option) any later version. 20 | % 21 | % This program is distributed in the hope that it will be useful, 22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | % GNU General Public License for more details. 25 | % 26 | % You should have received a copy of the GNU General Public License 27 | % along with this program; if not, write to the Free Software 28 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | % 30 | %-------------------------------------------------------------------------- 31 | 32 | close all; 33 | clear; 34 | 35 | % Initialization 36 | Fs = 8000; % Sample frequency (Hz) 37 | c = 340; % Sound velocity (m/s) 38 | K = 256; % FFT length 39 | M = 2; % Number of sensors 40 | d = 0.2; % Inter sensor distance (m) 41 | type_nf = 'spherical'; % Type of noise field: 42 | % 'spherical' or 'cylindrical' 43 | L = 10*Fs; % Data length 44 | 45 | %% Generate M mutually independent input signals of length L 46 | n = randn(L,M); 47 | 48 | %% Generate matrix with desired spatial coherence 49 | ww = 2*pi*Fs*(0:K/2)/K; 50 | DC = zeros(M,M,K/2+1); 51 | for p = 1:M 52 | for q = 1:M 53 | if p == q 54 | DC(p,q,:) = ones(1,1,K/2+1); 55 | else 56 | switch lower(type_nf) 57 | case 'spherical' 58 | DC(p,q,:) = sinc(ww*abs(p-q)*d/(c*pi)); 59 | 60 | case 'cylindrical' 61 | DC(p,q,:) = bessel(0,ww*abs(p-q)*d/c); 62 | 63 | otherwise 64 | error('Unknown noise field.') 65 | end 66 | end 67 | end 68 | end 69 | 70 | %% Generate sensor signals with desired spatial coherence 71 | % Mix signals 72 | x = mix_signals(n,DC,'cholesky'); 73 | 74 | %% Compare desired and generated coherence 75 | K_eval = 256; 76 | ww = 2*pi*Fs*(0:K_eval/2)/K_eval; 77 | sc_theory = zeros(M-1,K/2+1); 78 | sc_generated = zeros(M-1,K/2+1); 79 | % Calculate desired and generated coherence 80 | for m = 1:M-1 81 | switch lower(type_nf) 82 | case 'spherical' 83 | sc_theory(m,:) = sinc(ww*m*d/(c*pi)); 84 | 85 | case 'cylindrical' 86 | sc_theory(m,:) = bessel(0,ww*m*d/c); 87 | end 88 | 89 | [sc_tmp, Freqs]=cohere_mod(x(:,1),x(:,m+1),K_eval,Fs,hanning(K_eval),0.75*K_eval); 90 | sc_generated(m,:) = real(sc_tmp.'); 91 | end 92 | 93 | % Calculate mean square error 94 | MSE = zeros(M,1); 95 | for m = 1:M-1 96 | MSE(m) = 10*log10(sum(((sc_theory(m,:))-(sc_generated(m,:))).^2)./sum((sc_theory(m,:)).^2)); 97 | end 98 | 99 | % Plot spatial coherence of two sensor pairs 100 | figure(1); 101 | MM=min(2,M-1); 102 | for m = 1:MM 103 | subplot(MM,1,m); 104 | plot(Freqs/1000,sc_theory(m,:),'-k','LineWidth',1.5) 105 | hold on; 106 | plot(Freqs/1000,sc_generated(m,:),'-.b','LineWidth',1.5) 107 | hold off; 108 | xlabel('Frequency [kHz]'); 109 | ylabel('Spatial Coherence'); 110 | title(sprintf('Inter sensor distance %1.2f m',m*d)); 111 | legend('Theory',sprintf('Proposed Method (MSE = %2.1f dB)',MSE(m))); 112 | grid on; 113 | end -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/istft.m: -------------------------------------------------------------------------------- 1 | function x=istft(Y,nfft,dM,dN,wintype) 2 | % istft : Inverse Short Time Fourier Transform 3 | % ***************************************************************@ 4 | % Inputs: 5 | % Y, stft of x; 6 | % nfft, window length; 7 | % dM, sampling step in Time; 8 | % dN, sampling step in Frequency; 9 | % wintype, window type; 10 | % Inputs: 11 | % x, signal; 12 | % Usage: 13 | % x=istft(Y,nfft,dM,dN,wintype); 14 | % Defaults: 15 | % wintype='Hamming'; 16 | % dN = 1; 17 | % dM = 0.5*nfft; 18 | % nfft=2*(size(Y,1)-1); 19 | 20 | % Copyright (c) 2000. Dr Israel Cohen. 21 | % All rights reserved. Created 17/12/00. 22 | % ***************************************************************@ 23 | 24 | if nargin == 1 25 | nfft = 2*(size(Y,1)-1); 26 | end 27 | if nargin < 3 28 | dM = 0.5*nfft; 29 | dN = 1; 30 | end 31 | if nargin < 5 32 | wintype = 'Hamming'; 33 | end 34 | 35 | if exist(wintype) 36 | win=eval([lower(wintype),sprintf('(%g)',nfft)]); 37 | else 38 | error(['Undefined window type: ',wintype]) 39 | end 40 | 41 | N=nfft/dN; 42 | %extend the anti-symmetric range of the spectum 43 | %In case that the number of frequency bins is nfft/2+1 44 | if size(Y,1) ~= nfft 45 | Y(N/2+2:N,:)=conj(Y(N/2:-1:2,:)); 46 | end 47 | 48 | % Computes IDFT for each column of Y 49 | Y = ifft(Y); %Y=real(ifft(Y)); 50 | Y=Y((1:N)'*ones(1,dN),:); 51 | 52 | % Apply the synthesis window 53 | ncol=size(Y,2); 54 | Y = win(:,ones(1,ncol)).*Y; 55 | 56 | % Overlapp & add 57 | x=zeros((ncol-1)*dM+nfft,1); 58 | idx=(1:nfft)'; 59 | start=0; 60 | for l=1:ncol 61 | x(start+idx)=x(start+idx)+Y(:,l); 62 | start=start+dM; 63 | end 64 | 65 | % Cancelling the artificial delay at the beginning an end of the input 66 | % signal x[n] (see stft.m) 67 | % Note that we're not cancelling the delay at the end of the signal (because 68 | % we don't have nx - the length of x[n] before the zeros padding). Hence, 69 | % the reconstructed signal will 'suffer' from zeros padding at its end 70 | delay1 = nfft-1; 71 | x = x(delay1+1:end); -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/mix_signals.m: -------------------------------------------------------------------------------- 1 | function x = mix_signals(n,DC,method) 2 | 3 | % Mix M mutually indepedent signals such that the mixed signals 4 | % exhibit a specific spatial coherence. 5 | % 6 | % Input parameters: 7 | % n : M signals in the STFT domain [L x M] 8 | % DC : Desired coherence [M x M x K/2+1] 9 | % method : 'cholesky' or 'eigen' 10 | % 11 | % Output parameters: 12 | % x : M generated signals [L x M] 13 | % 14 | % Author : E.A.P. Habets 15 | % Date : 29-06-2017 16 | % 17 | % Reference : E.A.P. Habets, I. Cohen and S. Gannot, 'Generating 18 | % nonstationary multisensor signals under a spatial 19 | % coherence constraint', Journal of the Acoustical Society 20 | % of America, Vol. 124, Issue 5, pp. 2911-2917, Nov. 2008. 21 | 22 | % Copyright (C) 2009-2017 E.A.P. Habets 23 | % 24 | % This program is free software; you can redistribute it and/or modify 25 | % it under the terms of the GNU General Public License as published by 26 | % the Free Software Foundation; either version 2 of the License, or 27 | % (at your option) any later version. 28 | % 29 | % This program is distributed in the hope that it will be useful, 30 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 | % GNU General Public License for more details. 33 | % 34 | % You should have received a copy of the GNU General Public License 35 | % along with this program; if not, write to the Free Software 36 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 37 | 38 | narginchk(2,3); 39 | 40 | if nargin < 3 41 | method = 'cholesky'; 42 | end 43 | 44 | M = size(n,2); % Number of sensors 45 | L = size(n,1); % Length input signal 46 | K = (size(DC,3)-1)*2; 47 | 48 | % Short-time Fourier transform 49 | for m = 1 : M 50 | N(m,:,:) = stft(n(:,m), K, K/4, 1).'; 51 | end 52 | 53 | % Initialization 54 | C = zeros(size(DC)); % STFT mixing matrix 55 | X = zeros(size(N)); % STFT output matrix 56 | X(:,:,1) = X(1,1,1); 57 | 58 | % Generate output in the STFT domain for each frequency bin k 59 | for k = 2:K/2+1 60 | switch lower(method) 61 | case 'cholesky' 62 | C(:,:,k) = chol(DC(:,:,k)); 63 | 64 | case 'eigen' 65 | [V,D] = eig(DC(:,:,k)); 66 | C(:,:,k) = sqrt(D) * V'; 67 | 68 | otherwise 69 | error('Unknown method specified.'); 70 | end 71 | 72 | X(:,:,k) = C(:,:,k)' * N(:,:,k); 73 | end 74 | 75 | % Inverse STFT 76 | for m = 1 : M 77 | x(:,m) = real(istft(squeeze(X(m,:,:)).', K, K/4, 1)); 78 | end 79 | x = x(1:L,:); -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/stft.m: -------------------------------------------------------------------------------- 1 | function Y=stft(x,nfft,dM,dN,wintype) 2 | % stft : Short Time Fourier Transform 3 | % ***************************************************************@ 4 | % Inputs: 5 | % x, signal; 6 | % nfft, window length; 7 | % dM, sampling step in Time; 8 | % dN, sampling step in Frequency; 9 | % wintype, window type; 10 | % Usage: 11 | % Y=stft(x,nfft,dM,dN,wintype); 12 | % Defaults: 13 | % wintype='Hanning'; 14 | % dN = 1; 15 | % dM = 0.5*nfft; 16 | % nfft = minimum of 256 and the length of the signal; 17 | % Notes: 18 | % B = STFT(A,NFFT,dM,dN,WINTYPE) calculates the STFT 19 | % for the signal in vector A. The signal is split into 20 | % overlapping segments, each of which are windowed and then 21 | % Fourier transformed to produce an estimate of the 22 | % short-term frequency content of the signal. 23 | 24 | % Copyright (c) 2000. Dr Israel Cohen. 25 | % All rights reserved. Created 17/12/00. 26 | % ***************************************************************@ 27 | 28 | x = x(:); % make a column vector for ease later 29 | nx = length(x); 30 | if nargin == 1 31 | nfft = min(nx,256); 32 | end 33 | if nargin < 3 34 | dM = 0.5*nfft; 35 | dN = 1; 36 | end 37 | if nargin < 5 38 | wintype = 'Hamming'; 39 | end 40 | 41 | if exist(wintype) 42 | wins=eval([lower(wintype),sprintf('(%g)',nfft)]); 43 | else 44 | error(['Undefined window type: ',wintype]) 45 | end 46 | 47 | % find analysis window for the above synthesis window 48 | win=biorwin(wins,dM,dN); 49 | 50 | % make an artificial delay at the beginning an end of the input signal x[n] 51 | % in order to make an accurate STFT-ISTFT operation 52 | delay1 = nfft-1; 53 | delay2 = nfft-1; 54 | x = [zeros(delay1,1); x; zeros(delay2,1)]; 55 | nx = length(x); 56 | 57 | % figure out number of columns for offsetting the signal 58 | % this may truncate the last portion of the signal since we'd 59 | % rather not append zeros unnecessarily - also makes the fancy 60 | % indexing that follows more difficult. 61 | ncol = fix((nx-nfft)/dM+1); 62 | y = zeros(nfft,ncol); 63 | 64 | % now stuff x into columns of y with the proper offset 65 | % should be able to do this with fancy indexing! 66 | colindex = 1 + (0:(ncol-1))*dM; 67 | rowindex = (1:nfft)'; 68 | y(:) = x(rowindex(:,ones(1,ncol))+colindex(ones(nfft,1),:)-1); 69 | 70 | % apply the window to the array of offset signal segments 71 | y(:) = win(:,ones(1,ncol)).*y; 72 | 73 | % now fft y which does the columns 74 | N = nfft/dN; 75 | for k=1:dN-1 76 | y(1:N,:) = y(1:N,:) + y((1:N)+k*N,:); 77 | end 78 | y = y(1:N,:); 79 | y = fft(y); 80 | if ~any(any(imag(x))) 81 | y = y(1:N/2+1,:); 82 | end 83 | % take abs, and use image to display results 84 | if nargout == 0 85 | imagesc(abs(y));axis xy 86 | else 87 | Y = y; 88 | end -------------------------------------------------------------------------------- /lib/+sim/ANF-Generator-master/音轨-2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/+sim/ANF-Generator-master/音轨-2.wav -------------------------------------------------------------------------------- /lib/+sim/RIR_generator_URA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/+sim/RIR_generator_URA.m -------------------------------------------------------------------------------- /lib/+sim/gen_babble_speech.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/+sim/gen_babble_speech.m -------------------------------------------------------------------------------- /lib/+sim/generate_signal.m: -------------------------------------------------------------------------------- 1 | function [ x,varargin] = generate_signal( source,angle,r,distant,beta,varargin ) 2 | %---------------------------------------------------------------------- 3 | % generate micarray simulation signal 4 | %function 5 | % 6 | % Usage: (1) x = generate_signal( source,[90,0],0.032,1,0.2 ) 7 | % 8 | % Inputs: 9 | % source source signal 10 | % angle incident angle 11 | % r radius of array 12 | % beta reverberation parameter 13 | % varargin 14 | % varargin{1} scale of room-impulse-response 15 | % 16 | % Outputs: 17 | % x multi-channel signal 18 | % varargin{1} room-impulse-response 19 | % dependencies: 20 | % rir-generator 21 | % 22 | % Authors: Wang wei 23 | % $Revision: 0.0 $ $Date: $ 24 | % 25 | % --------------------------------------------------------------------- 26 | 27 | if nargin<2 28 | fprintf('Usage: [x]=generate_signal(source,angle) \n'); 29 | return; 30 | end; 31 | if nargin<3 32 | r = 0.032; 33 | end; 34 | if nargin<4 35 | distant = 1.0; 36 | end; 37 | if nargin<5 38 | beta = 0.2; 39 | end; 40 | if nargin==6 41 | scale = varargin{1}; 42 | else 43 | scale = 10; 44 | end; 45 | 46 | 47 | angle = [angle(1) angle(2)]/180*pi; % source direction [0,180] 48 | [x1,y1,z1]=sph2cart(angle(1),angle(2),distant); % source position 1 49 | source_pos = [x1,y1,z1]; % Source position [x y z] (m) 50 | 51 | N = 4; % number of sensor 52 | 53 | h = sim.RIR_generator_URA( source_pos,beta,r); 54 | h = h*scale; 55 | if 1 56 | x = zeros(length(source)+size(h,2)-1,N); 57 | for i=1:N 58 | x(:,i) = conv(source,h(i,:)); 59 | end 60 | else 61 | H = getRIR(); 62 | % H = H(:,[1,3],[2,5]); 63 | x = zeros(length(source)+size(H,1)-1,N); 64 | for i=1:N 65 | x(:,i) = conv(source,H(:,i+1)); 66 | end 67 | end 68 | 69 | 70 | 71 | if nargout>1 72 | varargin{1} = h; 73 | end 74 | 75 | end 76 | 77 | -------------------------------------------------------------------------------- /lib/+sim/noise_gen_URA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/+sim/noise_gen_URA.m -------------------------------------------------------------------------------- /lib/+sim/signal_simulation.m: -------------------------------------------------------------------------------- 1 | function [ sig ] = signal_simulation( r,slice ) 2 | % signal simulation function 3 | % 4 | % Usage: (1) [ sig ] = signal_simulation(0.064,[1,3]); 5 | % 6 | % Inputs: 7 | % r radius of circular array 8 | % slice choose which channel to use 9 | % varargin 10 | % arrayType array type,linear or circular,default linear 11 | % 12 | % Outputs: 13 | % sig 4-channel siganl [samples,channel] 14 | % 15 | % Created by Wang wei 16 | %% generate diffuse noise 17 | % [ noise,Pos] = sim.noise_gen_URA(r); 18 | addpath(genpath('ANF-Generator-master')); 19 | noise = sim.gen_babble_speech(4,r,5); 20 | % noise = noise'/500; 21 | %% signal simulation 22 | pathname = 'wav/'; 23 | 24 | % use a clean speech audio as desired signal 25 | [speech ,fs] = audioread([pathname,'S_01_01.wav']); 26 | [interference] = audioread([pathname,'S_72_09.wav']); 27 | 28 | s = sim.generate_signal(speech,[0,0],r,1,0.2); 29 | interf = sim.generate_signal(interference,[90,0],r,1,0.2); 30 | 31 | % signal+interference+diffuse noise 32 | len_min = min(min(size(s,1),size(interf,1)),size(noise,1)); 33 | % slice = [1,3]; 34 | clean_s = s(1:len_min,slice); 35 | clean_i = interf(1:len_min,slice); 36 | clean_n = noise(1:len_min,slice)/2; 37 | switch 1 38 | case 1 39 | x = clean_s+clean_i+clean_n; 40 | case 2 41 | x = clean_s+clean_i; 42 | clean_n = zeros(size(clean_n)); 43 | case 3 44 | x = clean_s; 45 | clean_i = zeros(size(clean_i)); 46 | clean_n = zeros(size(clean_n)); 47 | case 4 48 | % ideal signal 49 | len_min_clean = min(length(speech),length(interference)); 50 | speech = speech(1:len_min_clean); 51 | interference = interference(1:len_min_clean); 52 | clean_s = [speech(3:end),speech(1:end-2)]; 53 | clean_i = [interference(1:size(clean_s,1)),interference(1:size(clean_s,1))]; 54 | x = clean_s + clean_i; 55 | d = 0.0213*2; 56 | otherwise 57 | disp('other value') 58 | end 59 | 60 | SNR = snr(clean_s(:,1),clean_i(:,1)) 61 | 62 | sig.speech = speech; 63 | sig.clean_s = clean_s; 64 | sig.clean_i = clean_i; 65 | sig.clean_n = clean_n; 66 | sig.x = x; 67 | rmpath(genpath('./ANF-Generator-master')); 68 | end 69 | 70 | -------------------------------------------------------------------------------- /lib/+util/fig.m: -------------------------------------------------------------------------------- 1 | function fig(data_in, fs) 2 | 3 | if nargin == 1 4 | [data, fs] = audioread(data_in); 5 | filename = data_in; 6 | else 7 | data = data_in; 8 | end 9 | Fs = 8000; 10 | noverlap = 128 * fs / Fs; 11 | nfft= 256 * fs / Fs; 12 | 13 | figure; 14 | spectrogram(data/max(abs(data)), hamming(nfft),noverlap,nfft,fs,'yaxis') 15 | set(gcf, 'position', [1, 235, 1366, 400]); 16 | set(gca, 'position', [0.05, 0.12, 0.85, 0.8]); 17 | if exist('filename','var') 18 | title(filename, 'interpreter', 'none'); 19 | end 20 | 21 | -------------------------------------------------------------------------------- /lib/+util/play.m: -------------------------------------------------------------------------------- 1 | function player = play(varargin) 2 | 3 | if ischar(varargin{1}) 4 | [data, fs] = audioread(varargin{1}); 5 | if length(varargin) == 1 6 | normalizemode = 1; 7 | else 8 | normalizemode = varargin{2}; 9 | end 10 | else 11 | 12 | data = varargin{1}; 13 | fs = varargin{2}; 14 | if length(varargin) == 2 15 | normalizemode = 1; 16 | else 17 | normalizemode = varargin{3}; 18 | end 19 | end 20 | if normalizemode 21 | data = data / max(abs(data)); 22 | end 23 | player = audioplayer(data, fs); 24 | play(player) -------------------------------------------------------------------------------- /lib/+util/plot.m: -------------------------------------------------------------------------------- 1 | function handle = plot(data_in, fs) 2 | % 1) plotwav(data) 3 | % data is the wav filename including path 4 | % 2) plotwav(data, fs) 5 | 6 | if nargin == 1 7 | [data, fs] = audioread(data_in); 8 | else 9 | data = data_in; 10 | end 11 | if nargout == 1 12 | handle = figure; 13 | else 14 | figure; 15 | end 16 | plot((0 : length(data) - 1) / fs, data); 17 | xlim([0 , (length(data) / fs)]); 18 | xlabel('Time(Secs)') -------------------------------------------------------------------------------- /lib/+util/visual.m: -------------------------------------------------------------------------------- 1 | function [ output_args ] = visual( x,y ) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | %% visualization 4 | % 5 | % 6 | % example Usage: 7 | % x = stft( Y) 8 | % 9 | % 10 | % Inputs: 11 | % Y input time-frequency matrix,stored as [frameNum,half_bin] 12 | % nfft fft points 13 | % frameLength frame length 14 | % inc hop size 15 | % window analysis window 16 | % varargin 17 | % 18 | % 19 | % Outputs: 20 | % x time-domain data 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | 23 | if nargin == 1 24 | x = x(:); 25 | X = stft(x); 26 | X = abs(squeeze(X)'); 27 | figure, 28 | imagesc(10*log10(X)) 29 | set(gca,'YDir','normal') 30 | caxis([-50 10]) 31 | colorbar 32 | title('input signal') 33 | xlabel('frame') 34 | ylabel('frequeny') 35 | end 36 | 37 | if nargin == 2 38 | X = stft(x); 39 | Y = stft(y); 40 | X = abs(squeeze(X)'); 41 | Y = abs(squeeze(Y)'); 42 | figure, 43 | subplot(211) 44 | imagesc(10*log10(X)) 45 | set(gca,'YDir','normal') 46 | caxis([-50 10]) 47 | colorbar 48 | title('input signal') 49 | xlabel('frame') 50 | ylabel('frequeny') 51 | subplot(212) 52 | imagesc(10*log10(Y)) 53 | set(gca,'YDir','normal') 54 | caxis([-50 10]) 55 | colorbar 56 | title('output signal') 57 | xlabel('frame') 58 | ylabel('frequeny') 59 | end 60 | 61 | 62 | 63 | end 64 | 65 | -------------------------------------------------------------------------------- /lib/GenNoiseMSC.m: -------------------------------------------------------------------------------- 1 | function [ Fvv ] = GenNoiseMSC(M,N_FFT,fs,r,varargin) 2 | %GenNoiseMSC compute diffuse noise field Mignitude-SquareD Coherence 3 | %function 4 | % 5 | % Usage: (1) [ Fvv ] = GenNoiseMSC(M,N,fs,r,arrayType); 6 | % 7 | % Inputs: 8 | % M input channels 9 | % N_FFT fft points 10 | % fs sample frequency in Hz 11 | % r array aperture 12 | % varargin 13 | % arrayType array type,linear or circular,default linear 14 | % 15 | % Outputs: 16 | % Fvv [half_bin,M,M] coherence function 17 | if(nargin>4) 18 | arrayType = varargin{1}; 19 | else 20 | arrayType = 'linear'; 21 | end 22 | c = 340; 23 | f = 0:fs/256:fs/2; 24 | Fvv = zeros(N_FFT/2+1,M,M); 25 | k_optimal = 1; 26 | for i = 1:M 27 | for j = 1:M 28 | if i == j 29 | Fvv(:,i,j) = ones(N_FFT/2+1,1); 30 | else 31 | switch(lower(arrayType)) 32 | case 'linear' 33 | dij = abs(i-j)*r; 34 | case 'circular' 35 | mic_rad = abs(i-j)*(360/M)*pi/180; % radian between two sensor 36 | dij = np.sqrt(r^2+r^2-2*r*r*cos(mic_rad)); % distant between two sensor 37 | end 38 | Fvv(:,i,j) = sin(2*pi*f*dij*k_optimal/c)./(2*pi*f*dij*k_optimal/c);Fvv(1,i,j) = 0.998;%T(2) = 0.996; 39 | end 40 | % index = find(Fvv(:,i,j)>0.9); 41 | % if(size(index,1)>0) 42 | % Fvv(index,i,j)=0.9; 43 | % end 44 | end 45 | end 46 | 47 | end 48 | 49 | -------------------------------------------------------------------------------- /lib/GenNoiseMSC_shift.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/GenNoiseMSC_shift.m -------------------------------------------------------------------------------- /lib/istft.m: -------------------------------------------------------------------------------- 1 | function x = istft( Y,nfft,frameLength,inc,window,varargin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Inverse Short Time Fourier Transform 4 | % 5 | % 6 | % example Usage: 7 | % x = stft( Y) 8 | % 9 | % 10 | % Inputs: 11 | % Y input time-frequency matrix,stored as [frameNum,half_bin] 12 | % nfft fft points 13 | % frameLength frame length 14 | % inc hop size 15 | % window analysis window 16 | % varargin 17 | % 18 | % 19 | % Outputs: 20 | % x time-domain data 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | Y = squeeze(Y); 23 | if nargin == 1 24 | nfft = (size(Y,2)-1)*2; % data length 25 | end 26 | if nargin < 3 27 | frameLength = nfft; 28 | inc = frameLength/2; 29 | end 30 | if nargin < 5 31 | window = sqrt(hann(frameLength+1)); 32 | window = window(1:end-1); 33 | end 34 | 35 | frameNum = size(Y,1); % channel 36 | 37 | x = zeros(frameNum*inc+(frameLength-inc),1); 38 | 39 | for frameIndex = 1:frameNum 40 | Yt_half = Y(frameIndex,:); 41 | Yt = [Yt_half,conj(fliplr(Yt_half(2:end-1)))].'; 42 | xt = ifft(Yt,nfft).*window; % windowing 43 | % overlap-add 44 | x((frameIndex-1)*inc+1:(frameIndex-1)*inc+frameLength) = x((frameIndex-1)*inc+1:(frameIndex-1)*inc+frameLength) + xt; 45 | 46 | end 47 | 48 | end 49 | 50 | -------------------------------------------------------------------------------- /lib/mycohere.m: -------------------------------------------------------------------------------- 1 | function [Cxy, f] = mycohere(varargin) 2 | %COHERE Coherence function estimate. 3 | % Cxy = COHERE(X,Y,NFFT,Fs,WINDOW) estimates the coherence of X and Y 4 | % using Welch's averaged periodogram method. Coherence is a function 5 | % of frequency with values between 0 and 1 that indicate how well the 6 | % input X corresponds to the output Y at each frequency. X and Y are 7 | % divided into overlapping sections, each of which is detrended, then 8 | % windowed by the WINDOW parameter, then zero-padded to length NFFT. 9 | % The magnitude squared of the length NFFT DFTs of the sections of X and 10 | % the sections of Y are averaged to form Pxx and Pyy, the Power Spectral 11 | % Densities of X and Y respectively. The products of the length NFFT DFTs 12 | % of the sections of X and Y are averaged to form Pxy, the Cross Spectral 13 | % Density of X and Y. The coherence Cxy is given by 14 | % Cxy = (abs(Pxy).^2)./(Pxx.*Pyy) 15 | % Cxy has length NFFT/2+1 for NFFT even, (NFFT+1)/2 for NFFT odd, or NFFT 16 | % if X or Y is complex. If you specify a scalar for WINDOW, a Hanning 17 | % window of that length is used. Fs is the sampling frequency which does 18 | % not effect the cross spectrum estimate but is used for scaling of plots. 19 | % 20 | % [Cxy,F] = COHERE(X,Y,NFFT,Fs,WINDOW,NOVERLAP) returns a vector of freq- 21 | % uencies the same size as Cxy at which the coherence is computed, and 22 | % overlaps the sections of X and Y by NOVERLAP samples. 23 | % 24 | % COHERE(X,Y,...,DFLAG), where DFLAG can be 'linear', 'mean' or 'none', 25 | % specifies a detrending mode for the prewindowed sections of X and Y. 26 | % DFLAG can take the place of any parameter in the parameter list 27 | % (besides X and Y) as long as it is last, e.g. COHERE(X,Y,'mean'); 28 | % 29 | % COHERE with no output arguments plots the coherence in the current 30 | % figure window. 31 | % 32 | % The default values for the parameters are NFFT = 256 (or LENGTH(X), 33 | % whichever is smaller), NOVERLAP = 0, WINDOW = HANNING(NFFT), Fs = 2, 34 | % P = .95, and DFLAG = 'none'. You can obtain a default parameter by 35 | % leaving it off or inserting an empty matrix [], e.g. 36 | % COHERE(X,Y,[],10000). 37 | % 38 | % See also PSD, CSD, TFE. 39 | % ETFE, SPA, and ARX in the Identification Toolbox. 40 | 41 | % Author(s): T. Krauss, 3-31-93 42 | % Copyright (c) 1988-98 by The MathWorks, Inc. 43 | % $Revision: 1.1 $ $Date: 1998/06/03 14:42:19 $ 44 | 45 | narginchk(2,7); 46 | x = varargin{1}; 47 | y = varargin{2}; 48 | %[msg,nfft,Fs,window,noverlap,p,dflag]=psdchk(varargin(3:end),x,y); 49 | %error(msg) 50 | nfft = varargin{3}; 51 | Fs =varargin{4}; 52 | window=hanning(nfft); 53 | noverlap = 0.75*nfft; 54 | p = .95; 55 | dflag = 'none'; 56 | 57 | % compute PSD and CSD 58 | window = window(:); 59 | n = length(x); % Number of data points 60 | nwind = length(window); % length of window 61 | if n < nwind % zero-pad x , y if length is less than the window length 62 | x(nwind)=0; 63 | y(nwind)=0; 64 | n=nwind; 65 | end 66 | x = x(:); % Make sure x is a column vector 67 | y = y(:); % Make sure y is a column vector 68 | k = fix((n-noverlap)/(nwind-noverlap)); % Number of windows 69 | % (k = fix(n/nwind) for noverlap=0) 70 | index = 1:nwind; 71 | 72 | Pxx = zeros(nfft,1); Pxx2 = zeros(nfft,1); 73 | Pyy = zeros(nfft,1); Pyy2 = zeros(nfft,1); 74 | Pxy = zeros(nfft,1); Pxy2 = zeros(nfft,1); 75 | for i=1:k 76 | if strcmp(dflag,'none') 77 | xw = window.*x(index); 78 | yw = window.*y(index); 79 | elseif strcmp(dflag,'linear') 80 | xw = window.*detrend(x(index)); 81 | yw = window.*detrend(y(index)); 82 | else 83 | xw = window.*detrend(x(index),0); 84 | yw = window.*detrend(y(index),0); 85 | end 86 | index = index + (nwind - noverlap); 87 | Xx = fft(xw,nfft); 88 | Yy = fft(yw,nfft); 89 | Xx2 = abs(Xx).^2; 90 | Yy2 = abs(Yy).^2; 91 | Xy2 = Yy.*conj(Xx); 92 | Pxx = Pxx + Xx2; 93 | Pxx2 = Pxx2 + abs(Xx2).^2; 94 | Pyy = Pyy + Yy2; 95 | Pyy2 = Pyy2 + abs(Yy2).^2; 96 | Pxy = Pxy + Xy2; 97 | Pxy2 = Pxy2 + Xy2.*conj(Xy2); 98 | end 99 | 100 | % Select first half 101 | if ~any(any(imag([x y])~=0)), % if x and y are not complex 102 | if rem(nfft,2), % nfft odd 103 | select = [1:(nfft+1)/2]; 104 | else 105 | select = [1:nfft/2+1]; % include DC AND Nyquist 106 | end 107 | Pxx = Pxx(select); 108 | Pxx2 = Pxx2(select); 109 | Pyy = Pyy(select); 110 | Pyy2 = Pyy2(select); 111 | Pxy = Pxy(select); 112 | Pxy2 = Pxy2(select); 113 | else 114 | select = 1:nfft; 115 | end 116 | %Coh = (abs(Pxy).^2)./(Pxx.*Pyy); % coherence function estimate 117 | Coh = Pxy./sqrt(Pxx.*Pyy); 118 | freq_vector = (select - 1)'*Fs/nfft; 119 | 120 | % set up output parameters 121 | if (nargout == 2), 122 | Cxy = Coh; 123 | f = freq_vector; 124 | elseif (nargout == 1), 125 | Cxy = Coh; 126 | elseif (nargout == 0), % do a plot 127 | newplot; 128 | plot(freq_vector,Coh), grid on 129 | xlabel('Frequency'), ylabel('Coherence Function Estimate'); 130 | end -------------------------------------------------------------------------------- /lib/patternURA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/lib/patternURA.m -------------------------------------------------------------------------------- /lib/spectral_subtraction.m: -------------------------------------------------------------------------------- 1 | %SPECTRAL_SUBTRACTION Compute spectral subtraction weights. 2 | % 3 | % weights = spectral_subtraction(SNR,alpha,beta,mu,Gmin) 4 | % 5 | % alpha = 1; beta = 1; % power subtraction 6 | % alpha = 2; beta = 0.5; % magnitude subtraction 7 | % alpha = 2; beta = 1; % Wiener filter 8 | % mu: noise overestimation 9 | % Gmin: gain floor 10 | % 11 | % Andreas Schwarz (schwarz@lnt.de) 12 | % Multimedia Communications and Signal Processing 13 | % Friedrich-Alexander-Universitaet Erlangen-Nuernberg (FAU) 14 | % Cauerstr. 7, 91058 Erlangen, Germany 15 | function weights = spectral_subtraction(SNR,alpha,beta,mu,Gmin) 16 | 17 | if (nargin == 1) 18 | % default: magnitude subtraction 19 | alpha = 2; 20 | beta = 0.5; 21 | mu = 1; 22 | end 23 | 24 | if ~exist('Gmin','var') 25 | Gmin = 0.1; 26 | end 27 | 28 | SNR = max(SNR,0); 29 | weights = max(1 - (mu./(SNR + 1)).^beta, 0).^alpha; 30 | weights = max(weights,0); 31 | weights = max(sqrt(weights),Gmin); 32 | 33 | end -------------------------------------------------------------------------------- /lib/stft.m: -------------------------------------------------------------------------------- 1 | function Y = stft( x,nfft,frameLength,inc,window,varargin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Multi-Channle Short Time Fourier Transform 4 | % 5 | % 6 | % example Usage: 7 | % Y = stft( x,256,256,128) 8 | % 9 | % Inputs: 10 | % x input data,stored in column-wise 11 | % nfft fft points 12 | % frameLength frame length 13 | % inc hop size 14 | % window analysis window 15 | % varargin 16 | % 17 | % 18 | % Outputs: 19 | % Y STFT matrix,[frameNum,channel,half_bin] 20 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 21 | 22 | % x = x(:); % make a column vector for ease later 23 | 24 | if nargin == 1 25 | nfft = 256; 26 | end 27 | if nargin < 3 28 | frameLength = nfft; 29 | inc = frameLength/2; 30 | end 31 | if nargin < 5 32 | window = sqrt(hann(frameLength+1)); 33 | window = window(1:end-1); 34 | end 35 | 36 | 37 | M = size(x,2); % channel 38 | dataLength = size(x,1); % data length 39 | 40 | half_bin = nfft/2+1; 41 | 42 | frameNum = fix((dataLength - (frameLength-inc))/inc); % Number of frame 43 | 44 | Y = zeros(frameNum,M,half_bin); % outout STFT matrrix 45 | 46 | for frameIndex = 1:frameNum 47 | xt = x((frameIndex-1)*inc+1:(frameIndex-1)*inc+frameLength,:); % enframe 48 | xt = xt.*window; % windowing 49 | Xt = fft(xt,nfft); % fft 50 | Y(frameIndex,:,:) = Xt(1:half_bin,:).'; 51 | end 52 | 53 | end 54 | 55 | -------------------------------------------------------------------------------- /lib/stft_test.m: -------------------------------------------------------------------------------- 1 | [x,fs] = audioread('S_01_01.wav'); 2 | 3 | % x = [zeros(128,1);x]; 4 | Y = stft(x); 5 | 6 | x_rec = istft(Y); 7 | 8 | % Y = stftanalysis(x,256,128); 9 | % 10 | % x_rec = stftsynthesis(Y,256,128); 11 | -------------------------------------------------------------------------------- /lib/update_CSD.m: -------------------------------------------------------------------------------- 1 | function [ Pxij ] = update_CSD( X,alpha,Pxij) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % calculate cross-spectral power density 4 | % 5 | % 6 | % example Usage: 7 | % [ Pxij ] = update_CSD( X,alpha,Pxij) 8 | % 9 | % Inputs: 10 | % X Multichannel input data,stored in column-wise 11 | % alpha average factor 12 | % Pxij last Pxij,size of [N(N-1)/2,half_bin] 13 | % 14 | % 15 | % Outputs: 16 | % Pxij recursively averaged CSD 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | N = size(X,1); % channel 19 | for i = 1:N 20 | for j = 1:N 21 | Xi = X(i,:); 22 | Xj = X(j,:); 23 | if(i==j) 24 | Fvv(i,j,:) = 1; 25 | else 26 | Pxij_i_j = squeeze(Pxij(i,j,:)).'; 27 | Pxij(i,j,:) = alpha*Pxij_i_j+(1-alpha)*Xi.*conj(Xj); 28 | 29 | end 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /lib/update_MSC.m: -------------------------------------------------------------------------------- 1 | function [ P ] = update_MSC(X,P,alpha,varargin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % calculate coherence function 4 | % 5 | % 6 | % example Usage: 7 | % [ Pxii,Pxij,Fvv ] = update_MSC(X,Pxii,Pxij,Fvv,alpha) 8 | % 9 | % Inputs: 10 | % X Multichannel input data,size of [channel,half_bin] 11 | % alpha average factor 12 | % Pxii previous Pxii,size of [N(N-1)/2,half_bin] 13 | % Pxij previous Pxij,size of [N(N-1)/2,half_bin] 14 | % Fvv previous Fvv,size of [N,N,,half_bin] 15 | % varargin 16 | % alpha_MSC MSC average factor 17 | % 18 | % 19 | % Outputs: 20 | % Pxii,Pxij,Fvv recursively averaged Pxii,Pxij,Fvv 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | 23 | N = size(X,1); % channel 24 | 25 | 26 | if nargin <3 27 | alpha = 0.6; 28 | end 29 | if nargin ==4 30 | alpha_MSC = varargin{1}; 31 | else 32 | alpha_MSC = 0; 33 | end 34 | 35 | Pxii = P.Pxii; 36 | Pxij = P.Pxij; 37 | Fvv = P.Fvv; 38 | 39 | % Pxii = update_PSD(X,alpha,Pxii); 40 | % Pxij = update_CSD(X,alpha,Pxij); 41 | 42 | for i = 1:N 43 | Xi = X(i,:); 44 | % update auto-spectral power density 45 | Pxii(i,:) = alpha*Pxii(i,:)+(1-alpha)*Xi.*conj(Xi); 46 | end 47 | for i = 1:N 48 | for j = 1:N 49 | Xi = X(i,:); 50 | Xj = X(j,:); 51 | if(i==j) 52 | Fvv(i,j,:) = 1; 53 | else 54 | Pxij_i_j = squeeze(Pxij(i,j,:)).'; 55 | Pxij(i,j,:) = alpha*Pxij_i_j+(1-alpha)*Xi.*conj(Xj); 56 | Pxij_i_j = squeeze(Pxij(i,j,:)).'; 57 | 58 | % complex coherence function 59 | Fvv_i_j_curr = Pxij_i_j./(sqrt(Pxii(i,:).*Pxii(j,:))); 60 | 61 | Fvv_i_j = squeeze(Fvv(i,j,:)).'; 62 | Fvv(i,j,:) = alpha_MSC*Fvv_i_j+(1-alpha_MSC)*Fvv_i_j_curr; 63 | % Fvv_i_j_t = Pxij(t,:)./(sqrt(Pxii(i,:).*Pxii(j,:))); 64 | end 65 | end 66 | end 67 | 68 | P.Pxii = Pxii; 69 | P.Pxij = Pxij; 70 | P.Fvv = Fvv; 71 | 72 | -------------------------------------------------------------------------------- /lib/update_PSD.m: -------------------------------------------------------------------------------- 1 | function [ Pxii ] = update_PSD( X,alpha,Pxii) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % calculate auto-spectral power density 4 | % 5 | % 6 | % example Usage: 7 | % [ Pxii ] = update_PSD( X,alpha,Pxii) 8 | % 9 | % Inputs: 10 | % X Multichannel input data,stored in column-wise 11 | % alpha average factor 12 | % Pxii last Pxii,size of [N(N-1)/2,half_bin] 13 | % 14 | % 15 | % Outputs: 16 | % Pxii recursively averaged PSD 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | N = size(X,1); % channel 19 | for i = 1:N 20 | Xi = X(i,:); 21 | % update auto-spectral power density 22 | Pxii(i,:) = alpha*Pxii(i,:)+(1-alpha)*Xi.*conj(Xi); 23 | end 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /plotSNR.m: -------------------------------------------------------------------------------- 1 | function [ output_args ] = plotSNR( SNR ) 2 | % plot SNR 3 | %function 4 | % 5 | % Usage: (1) plotSNR( SNR ); 6 | % 7 | % Inputs: 8 | % SNR SNR ,[frameIndex,frequency] 9 | % N_FFT fft points 10 | % fs sample frequency in Hz 11 | % r array aperture 12 | % varargin 13 | % arrayType array type,linear or circular,default linear 14 | % 15 | % Outputs: 16 | % Fvv [half_bin,M,M] coherence function 17 | SNR = SNR'; 18 | % figure,imagesc([1:size(SNR,1)]*128,[1:size(SNR,2)],10*log10(flipud(abs(SNR)))); 19 | imagesc([1:size(SNR,2)]*128,[1:size(SNR,1)]*16000/256,10*log10(abs(SNR))); 20 | set(gca,'YDir','normal') 21 | title('SNR') 22 | xlabel('sample') 23 | ylabel('frequeny') 24 | caxis([-10 10]) 25 | colorbar 26 | end 27 | 28 | -------------------------------------------------------------------------------- /process.m: -------------------------------------------------------------------------------- 1 | function [ y,Fvv,SNR] = process(x,d,varargin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Frequency domain processing function 4 | % 5 | % input : 6 | % x : input signal ,samples * channel 7 | % fs: sample rate 8 | % N : fft length,frequency bin number 9 | %frameLength : frame length,usually same as N 10 | % inc : step increment 11 | % d : array element spacing 12 | % angle : incident angle 13 | % 14 | % output : 15 | % MVDRout : MVDR output 16 | % x1 : presteered signal,same size as x 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | if nargin==3 19 | method = varargin{1}; 20 | else 21 | method = 3; 22 | end; 23 | 24 | X = stft(x,512,512,256); 25 | N_FFT = (size(X,3)-1)*2; 26 | N = size(x,2); 27 | half_bin = size(X,3); 28 | 29 | P.Pxii = ones(N,half_bin); 30 | P.Pxij = ones(N,N,half_bin); 31 | P.Fvv = zeros(N,N,half_bin); 32 | 33 | G = zeros(1,half_bin); 34 | SNR = zeros(size(X,1),half_bin); 35 | 36 | % output spectral 37 | Y = squeeze(X(:,1,:)); 38 | 39 | alpha = 0.60; 40 | alpha_MSC = 0; 41 | 42 | iNumFilts = 40; 43 | %aad_H = ComputeFilterResponse(iNumFilts, N_FFT); 44 | 45 | for frameIndex = 1:size(X,1) 46 | X_t = squeeze(X(frameIndex,:,:)); 47 | P = update_MSC(X_t,P,alpha,alpha_MSC); 48 | 49 | Gmin = 0.1; 50 | % method = 5; %3/5 51 | for k = 1:half_bin 52 | [G(k),SNR(frameIndex,k)] = getweights(P.Fvv,k,d,Gmin,method); 53 | % G(k) = sqrt(G(k)); 54 | end 55 | ad_X_Bar = squeeze(mean(X(frameIndex,:,:))).'; 56 | G(1:16) = sqrt(G(1:16)); 57 | % [aad_X_tilde] = ChannelWeighting(ad_X_Bar,G,aad_H); 58 | 59 | % aad_X_tilde(1:8) = ad_X_Bar(1:8); 60 | % Y(frameIndex,:) = aad_X_tilde; 61 | Y(frameIndex,:) = Y(frameIndex,:).*G; 62 | % Y(frameIndex,:) = squeeze(mean(X(frameIndex,:,:))).'.*G; 63 | 64 | end 65 | y = istft(Y,512,512,256); 66 | scale = 1.5; 67 | y = real(y)*scale; 68 | Fvv = P.Fvv; 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /process_SNR.m: -------------------------------------------------------------------------------- 1 | function [ y,Fvv,SNR,SNR_predict,P_s,P_i,P_x,Fvv_all_est] = process_SNR(s,interf,d) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Frequency domain processing function 4 | % 5 | % input : 6 | % x : input signal ,samples * channel 7 | % fs: sample rate 8 | % N : fft length,frequency bin number 9 | %frameLength : frame length,usually same as N 10 | % inc : step increment 11 | % d : array element spacing 12 | % angle : incident angle 13 | % 14 | % output : 15 | % MVDRout : MVDR output 16 | % x1 : presteered signal,same size as x 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | X_source = stft(s); 20 | X_interf = stft(interf); 21 | X_noisy = stft(s+interf); 22 | N = size(s,2); 23 | half_bin = size(X_source,3); 24 | 25 | frames = size(X_source,1); 26 | 27 | P_s.Pxii = ones(N,half_bin); 28 | P_s.Pxij = ones(N,N,half_bin); 29 | P_s.Fvv = zeros(N,N,half_bin); 30 | P_s.Fvv_all = zeros(frames,N,N,half_bin); 31 | 32 | P_i.Pxii = ones(N,half_bin); 33 | P_i.Pxij = ones(N,N,half_bin); 34 | P_i.Fvv = zeros(N,N,half_bin); 35 | P_i.Fvv_all = zeros(frames,N,N,half_bin); 36 | 37 | P_x.Pxii = ones(N,half_bin); 38 | P_x.Pxij = ones(N,N,half_bin); 39 | P_x.Fvv = zeros(N,N,half_bin); 40 | P_x.Fvv_all = zeros(frames,N,N,half_bin); 41 | 42 | Fvv_all_est = zeros(frames,N,N,half_bin); 43 | 44 | G = zeros(1,half_bin); 45 | 46 | % output spectral 47 | Y = squeeze(X_noisy(:,1,:)); 48 | 49 | SNR_L = zeros(size(X_source,1),half_bin); 50 | SNR_R = zeros(size(X_source,1),half_bin); 51 | SNR = zeros(size(X_source,1),half_bin); 52 | SNR_predict = zeros(size(X_source,1),half_bin); 53 | 54 | fs = 16000; 55 | c = 340; 56 | f = 0:fs/256:fs/2; 57 | 58 | N_FFT = 256; 59 | k = 0:1:N_FFT/2; 60 | % k = k(2:end); 61 | omega = 2*pi*k/N_FFT; 62 | 63 | % omega = 2*pi*f/fs; 64 | tau = fs*d/c; 65 | 66 | alpha = 0.8; 67 | alpha_MSC = 0; 68 | % X_interf = X_source; 69 | Gmin = 0.1; 70 | method = 2; 71 | for frameIndex = 1:size(X_source,1) 72 | 73 | SNR_L(frameIndex,:) = real(P_s.Pxii(1,:)./P_i.Pxii(1,:)); 74 | SNR_R(frameIndex,:) = real(P_s.Pxii(2,:)./P_i.Pxii(2,:)); 75 | SNR(frameIndex,:) = real(P_s.Pxii(1,:)./P_i.Pxii(1,:)); 76 | 77 | X_s = squeeze(X_source(frameIndex,:,:)); 78 | P_s = update_MSC(X_s,P_s,alpha,alpha_MSC); 79 | P_s.Fvv_all(frameIndex,:,:,:) = P_s.Fvv; 80 | 81 | X_i = squeeze(X_interf(frameIndex,:,:)); 82 | P_i = update_MSC(X_i,P_i,alpha,alpha_MSC); 83 | P_i.Fvv_all(frameIndex,:,:,:) = P_i.Fvv; 84 | 85 | X_x = squeeze(X_noisy(frameIndex,:,:)); 86 | P_x = update_MSC(X_x,P_x,alpha,alpha_MSC); 87 | P_x.Fvv_all(frameIndex,:,:,:) = P_x.Fvv; 88 | 89 | 90 | % Fvv_all_est(frameIndex,1,2,:) = squeeze(P_s.Fvv(1,2,:)).'.*SNR(frameIndex,:)./(SNR(frameIndex,:)+1)+... 91 | % squeeze(P_i.Fvv(1,2,:)).'./(SNR(frameIndex,:)+1); 92 | Fvv_all_est(frameIndex,1,2,:) = exp(1j*omega*tau).*SNR(frameIndex,:)./(SNR(frameIndex,:)+1)+... 93 | 1./(SNR(frameIndex,:)+1); 94 | for k = 1:half_bin 95 | [G(k),SNR_predict(frameIndex,k)] = getweights(P_x.Fvv,k,d,Gmin,method); 96 | end 97 | % G = sqrt(SNR(frameIndex,k)./(1+SNR(frameIndex,k))); 98 | 99 | Y(frameIndex,:) = Y(frameIndex,:).*G; 100 | 101 | end 102 | y = istft(Y); 103 | Fvv = P_s.Fvv; 104 | 105 | end 106 | 107 | -------------------------------------------------------------------------------- /wav/COH_CT_90.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/COH_CT_90.wav -------------------------------------------------------------------------------- /wav/STEREO_0024.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/STEREO_0024.pcm -------------------------------------------------------------------------------- /wav/S_01_01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/S_01_01.wav -------------------------------------------------------------------------------- /wav/S_01_01_rec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/S_01_01_rec.wav -------------------------------------------------------------------------------- /wav/S_72_09.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/S_72_09.wav -------------------------------------------------------------------------------- /wav/Unp_Front_CT_90.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/Unp_Front_CT_90.wav -------------------------------------------------------------------------------- /wav/Unp_Rear_CT_90.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/Unp_Rear_CT_90.wav -------------------------------------------------------------------------------- /wav/xmos/rec/readme.txt: -------------------------------------------------------------------------------- 1 | target:0 2 | interf:270 -------------------------------------------------------------------------------- /wav/xmos/rec/音轨-2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec/音轨-2.wav -------------------------------------------------------------------------------- /wav/xmos/rec/音轨-3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec/音轨-3.wav -------------------------------------------------------------------------------- /wav/xmos/rec/音轨-4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec/音轨-4.wav -------------------------------------------------------------------------------- /wav/xmos/rec/音轨-5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec/音轨-5.wav -------------------------------------------------------------------------------- /wav/xmos/rec96/readme.txt: -------------------------------------------------------------------------------- 1 | target:0 2 | inferf:270 -------------------------------------------------------------------------------- /wav/xmos/rec96/音轨-2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec96/音轨-2.wav -------------------------------------------------------------------------------- /wav/xmos/rec96/音轨-3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec96/音轨-3.wav -------------------------------------------------------------------------------- /wav/xmos/rec96/音轨-4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec96/音轨-4.wav -------------------------------------------------------------------------------- /wav/xmos/rec96/音轨-5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangwei2009/coherence/71c850509deb7904bcf6f294a854e8401694d652/wav/xmos/rec96/音轨-5.wav --------------------------------------------------------------------------------