/* void complex_divide(float Hn[2], float Hd[2], float H[2]) { float magn = sqrt(Hn[0]*Hn[0] + Hn[1]*Hn[1]); float argn = atan2(Hn[1],Hn[0]); float magd = sqrt(Hd[0]*Hd[0] + Hd[1]*Hd[1]); float argd = atan2(Hd[1],Hd[0]); float mag = magn/magd; float arg = argn - argd; H[0] = mag*cos(arg); H[1] = mag*sin(arg); } */ float groupdelay(Filter *c, float f, float Fs) { float df = 5; float f2 = f + df; float f1 = f - df; float omega2 = 2*PI*f2/Fs; float omega1 = 2*PI*f1/Fs; return (omega2*phasedelay(c,f2,Fs) - omega1*phasedelay(c,f1,Fs))/(omega2-omega1); }
void dwgs :: init(float f, float B, float inpos) { this->f = f; float deltot = Fs/f; int del1 = (int)(inpos*0.5*deltot); if(del1 < 2) del1 = 1; if(M==1) { thiriandispersion(B,f,M,&(dispersion[0])); } else if(M==4) { for(int m=0;m<M;m++) { thiriandispersion(B,f,M,&(dispersion[m])); } } float dispersiondelay = M*phasedelay(&(dispersion[0]),f,Fs); float lowpassdelay = .002; int del2 = (int)(0.5*(deltot-2.0*del1)-dispersiondelay); int del3 = (int)(0.5*(deltot-2.0*del1)-lowpassdelay-5.0); if(del2 < 2) del2 = 1; if(del3 < 2) del3 = 1; float D = (deltot-(float)(del1+del1+del2+del3)-dispersiondelay-lowpassdelay); if(D<1) D=1; thirian(D,(int)D,&fracdelay); d[0]->set_delay(del1,del1); d[1]->set_delay(del2,del3); //float tuningdelay = phasedelay(&fracdelay,f,Fs); // printf("total delay = %g/%g, leftdel = %d/%d, rightdel = %d/%d, dispersion delay = %g, lowpass delay = %g, fractional delay = %g/%g\n",del1+del1+del2+del3+dispersiondelay+lowpassdelay+tuningdelay,deltot, del1, del1, del2, del3, dispersiondelay, lowpassdelay, tuningdelay,D); }