%clear all; clc;

%racs=[1 2 3 3 3 3 3 4 5; ...
%    6 7 8 9 9 9 10 11 12; ...
%    13 14 15 16 17 18 19 20 21; ...
%    22 23 24 25 17 26 27 28 29; ...
%    30 31 32 33 17 34 35 36 37];

%x1=2.7;
%x2=3.6;
% DTW pattern illesztés
%dpath='C:\HIL\LisztZeneakademia_Nagyterem\Impulse\';
%mic='R';
%fs=48000; bit=32;
%N=fs*3;
%NFFT=2048;

function [IR12,IR34,IR1234]=dokt_ir4interp_v21(dpath,mic,fs,bit,pos1,pos2,pos3,pos4,w1,w2)

OFFS=0;
TWIN=3*14;
%-----------

wx1=w1;
wx2=1-w1;
wy1=w2;
wy2=1-w2;

file1=dir([dpath,'\*_',num2str(pos1),'_*',mic,'*c1*.wav']);
file2=dir([dpath,'\*_',num2str(pos2),'_*',mic,'*c1*.wav']);
file3=dir([dpath,'\*_',num2str(pos3),'_*',mic,'*c1*.wav']);
file4=dir([dpath,'\*_',num2str(pos4),'_*',mic,'*c1*.wav']);

IR1=wavread([dpath file1.name]);
IR2=wavread([dpath file2.name]);
IR3=wavread([dpath file3.name]);
IR4=wavread([dpath file4.name]);

[IRr,IRi,IR12]=dokt_ir2interp_v2(IR1,IR2,fs,bit,wx1,OFFS,TWIN);
[IRr,IRi,IR34]=dokt_ir2interp_v2(IR3,IR4,fs,bit,wx1,OFFS,TWIN);
[IRr,IRi,IR1234]=dokt_ir2interp_v2(IR12,IR34,fs,bit,wy1,OFFS,TWIN);

figure(2); clf; hold all; 
LIM1=1800; LIM2=3600; kicsi=-max(abs(IR1)); nagy=-kicsi;
subplot(3,2,1);
plot(IR1); set(gca,'Xlim',[LIM1 LIM2]); set(gca,'Ylim',[kicsi nagy]);
subplot(3,2,2);
plot(IR2); set(gca,'Xlim',[LIM1 LIM2]); set(gca,'Ylim',[kicsi nagy]);
subplot(3,2,3);
plot(IR3); set(gca,'Xlim',[LIM1 LIM2]); set(gca,'Ylim',[kicsi nagy]);
subplot(3,2,4);
plot(IR4); set(gca,'Xlim',[LIM1 LIM2]); set(gca,'Ylim',[kicsi nagy]);
subplot(3,1,3);
plot(IR1234); set(gca,'Xlim',[LIM1 LIM2]); set(gca,'Ylim',[kicsi nagy]);
hold off; 
