Browse Source

Transférer les fichiers vers ''

Matthieu PUIGT 6 months ago
parent
commit
6cbe3f1879
5 changed files with 148 additions and 0 deletions
  1. 29 0
      conv_mix.m
  2. 37 0
      hrtf.m
  3. 27 0
      laplace.m
  4. 42 0
      permutations.m
  5. 13 0
      sir.m

+ 29 - 0
conv_mix.m

@@ -0,0 +1,29 @@
+function x=conv_mix(A,s);
+
+% Convolutive mixing process - V1.2
+%
+% Inputs
+% A : mixing tensor whose A(i,j,:) element is the filter associated to the
+% j^th source and to the i^th observation
+% s : source vector
+%
+% Output
+% x : observation vector
+%
+% -------------------------------------------------------------------------
+% History of the software:
+% V1.1: original software written by J. Thomas
+%
+% V1.2: Error messages appeared with recent releases of Matlab in the function
+% conv_mix. This version corrects them. 
+% Author: Matthieu PUIGT   Contact: matthieu.puigt@univ-littoral.fr
+%
+% -------------------------------------------------------------------------
+
+x=zeros(size(A,1),size(s,2));
+
+for i=1:size(A,1)
+    for j=1:size(s,1)
+        x(i,:)=x(i,:)+filter(reshape(A(i,j,:),size(A,3),1,1),1,s(j,:));
+    end
+end

+ 37 - 0
hrtf.m

@@ -0,0 +1,37 @@
+% Load HRTF (Head Related Transfer Functions) for a given azimuth.
+% B. Gardner and K. Martin. Head Related Transfer Functions of a Dummy Head
+% http://sound.media.mit.edu/ica-bench/.
+
+function f = hrtf( az)
+
+% Bring in 0-360 degrees region
+while az > 360
+	az = az - 360;
+end
+while az < 0
+	az = az + 360;
+end
+
+% 180+x = flipped x
+flip = 0;
+if az > 180 
+	az = az - 180;
+	flip = 1;
+end
+
+% Load filters
+fname = sprintf( 'hrtf/H0e%.3da.dat', az);
+fid = fopen( fname, 'r', 'ieee-be');
+if fid == -1
+	error( sprintf( 'Cannot open file %s', fname));
+end
+tmp = fread( fid, inf, 'short');
+fclose( fid);
+
+% Assign to output and scale
+% filters are at 44100, decimate to the default 22050
+if ~flip
+	f = [decimate( tmp(1:2:end), 2)' ; decimate( tmp(2:2:end), 2)']/32767;
+else
+	f = [decimate( tmp(2:2:end), 2)' ; decimate( tmp(1:2:end), 2)']/32767;
+end

+ 27 - 0
laplace.m

@@ -0,0 +1,27 @@
+% Generation of Laplacian random i.i.d. processes
+%
+% Inputs
+% N : number of sources
+% T : number of samples
+
+% Outputs
+% s : source vector
+
+function s=laplace(N,T);
+
+TAU=1;
+
+s0=rand(N,T);
+r1=(s0<=0.5).*(log(2*s0)/TAU);
+r2=(s0>0.5).*(-log(2-2*s0)/TAU);
+s=r1+r2;
+
+s=cnorm(s);
+
+function s=cnorm(e)
+
+for k=1:size(e,1);
+s(k,:)=e(k,:)-mean(e(k,:));
+s(k,:)=s(k,:)./mean(s(k,:).^2)^0.5;
+end
+

+ 42 - 0
permutations.m

@@ -0,0 +1,42 @@
+function perm=permutations(xc,sc)
+
+% Identification of the source permutations between the true and estimated 
+% contributions tensors xc and sc
+%
+% Inputs
+% xc : tensor whose element xc(i,j,:) is the true contribution of the j^th
+% source in the i^th sensor
+% sc : tensor whose element sc(i,j,:) is the estimated contribution of the 
+% j^th permutated source in the i^th sensor
+%
+% Ouput
+% perm : permutation vector
+
+for r=1:size(xc,2)
+    
+s1(:,1,:)=xc(:,r,:);
+s2(:,:,:)=sc(:,:,:);
+
+perm(r)=ident(s1,s2);
+
+end
+
+%--------------------------------------------------------------------------
+
+function [i]=ident(s1,s2)
+
+for r=1:size(s2,2)
+    sir1(r)=0;
+    for k=1:size(s1,1);
+        sir1(r)=max(sir(s1(k,1,:),s2(k,r,:)),sir1(r));
+    end
+end
+
+[SIR,i]=max(sir1);
+
+%--------------------------------------------------------------------------
+
+function sir1=sir(s1,s2)
+
+sir1=10*log10(mean(s1.^2)/mean((s1-s2).^2));
+

+ 13 - 0
sir.m

@@ -0,0 +1,13 @@
+% Computation of the Signal to Interferences Ratio between the reference
+% signal s1 and its estimation s2.
+%
+% Inputs
+% s1 : reference signal
+% s2 : estimated signal
+%
+% Output
+% SIR : Signal to Interferences Ratio between s1 and s2 (dB)
+
+function SIR=sir(s1,s2)
+
+SIR=10*log10(mean(s1.^2)/mean((s1-s2).^2));