Bladeren bron

always make the filters minimum phase, trim the zero part and return just the real impulse response, write a tetraproc compatible wav file

Fernando Pablo Lopez-Lezcano 10 jaren geleden
bovenliggende
commit
c25c1e3870
1 gewijzigde bestanden met toevoegingen van 34 en 24 verwijderingen
  1. 34 24
      sphear_fir_design.m

+ 34 - 24
sphear_fir_design.m

@@ -43,8 +43,6 @@
 
 function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, plot_on, W, X, Y, Z)
 
-  minphase = 1;
-  
   if (plot_on != 0)
     fig = figure;
   end
@@ -219,30 +217,42 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, plot_on, W, X,
 	end
       end
 
-      %% design the filter
-      FIR(b, c, :) = fir2(n, fi, ri);
-      if (minphase != 0)
-	%% try to get it close to minimum phase
-	%%
-	%% "Two alternative minimum-phase filters tested perceptually"
-	%% Robert Mores and Ralf Hendrych, AES Convertion paper 9554
-	%%
-	IR = reshape(FIR(b, c, :), 257, 1);
-	%% number of samples in the sin transition
-	%%
-	%% 8 seems to be the sweet spot for a FIR filter size of 256,
-	%% 16 leads to bigger phase shift, 4 starts to impact negatively
-	%% the flattness of the frequency response
-	%%
-	N = 8;
-	M = size(IR)(1);
-	R = 0.5 + (0.5 * sin(pi * ((1:(2*N)) - N) / (2 * N)));
-	ramp = [zeros(M/2 - N + 1, 1); R'; ones(M/2 - N, 1)];
-	IRR = (IR .* ramp * 2);
-	FIR(b, c, :) = IRR(:);
-      end
+      %% design the filter and try to get it close to minimum phase
+      %%
+      %% "Two alternative minimum-phase filters tested perceptually"
+      %% Robert Mores and Ralf Hendrych, AES Convertion paper 9554
+      %%
+      IR = fir2(n, fi, ri)';
+      %% number of samples in the sin transition
+      %%
+      %% 8 seems to be the sweet spot for a FIR filter size of 256,
+      %% 16 leads to bigger phase shift, 4 starts to impact negatively
+      %% the flattness of the frequency response
+      %%
+      M = size(IR)(1);
+      N = (M-1)/32;
+      R = 0.5 + (0.5 * sin(pi * ((1:(2*N)) - N) / (2 * N)));
+      ramp = cat(1, zeros(M/2 - N + 1, 1), R', ones(M/2 - N, 1));
+      IRMP = IR .* ramp * 2;
+
+      %% now we trim the filter and return one that is 1/2 the size requested
+      %% we also window the end of the impulse response... (unnecessary?)
+      %% T = 4;
+      %% tapper = cat(1, ones(M/2 - 2*T + 1, 1), (1.0 - (0.5 + (0.5 * sin(pi * ((1:(2*T)) - T) / (2 * T)))))');
+      FIR(b, c, :) = IRMP((M-1)/2 - N:(M-1)/2 - N + (M-1)/2);
     end
   end
+
+  %% write a tetraproc compatible wav file
+  fuma = [sqrt(2)/2, 1, 1, 1];
+  for b = 1:4
+    TETRA(:, b) = fuma(b) * cat(1,
+				reshape(FIR(b, 1, :), 1, [])',
+				reshape(FIR(b, 2, :), 1, [])',
+				reshape(FIR(b, 3, :), 1, [])',
+				reshape(FIR(b, 4, :), 1, [])');
+  end
+  wavwrite(TETRA, Fs, 'calibration/tetraproc_matrix.wav');
   
   if (plot_on != 0)
     l = legend([wh, zh, xyh], {'W', 'XY', 'Z'});