private void updateViews() { Real1 h = computeImpulseResponse(); Real1[] ap = computeAmplitudeAndPhaseResponses(); Real1 a = ap[0]; Real1 p = ap[1]; if (_hView==null) { _hView = _plotPanelH.addSequence(h.getSampling(),h.getValues()); _aView = _plotPanelAP.addPoints(0,0,a.getSampling(),a.getValues()); _pView = _plotPanelAP.addPoints(1,0,p.getSampling(),p.getValues()); } else { _hView.set(h.getSampling(),h.getValues()); _aView.set(a.getSampling(),a.getValues()); _pView.set(p.getSampling(),p.getValues()); } }
private static Real1 binaryOp(Real1 ra, Real1 rb, Binary ab) { Sampling sa = ra.getSampling(); Sampling sb = rb.getSampling(); Check.argument(sa.isEquivalentTo(sb),"samplings equivalent"); Sampling sc = sa; Real1 rc = new Real1(sc); float[] va = ra.getValues(); float[] vb = rb.getValues(); float[] vc = rc.getValues(); ab.apply(vc.length,va,0,vb,0,vc,0); return rc; } private static Real1 binaryOp(float ar, Real1 rb, Binary ab) {
private static Real1 binaryOp(float ar, Real1 rb, Binary ab) { Sampling sb = rb.getSampling(); Sampling sc = sb; Real1 rc = new Real1(sc); float[] vb = rb.getValues(); float[] vc = rc.getValues(); ab.apply(vc.length,ar,vb,0,vc,0); return rc; } private static Real1 binaryOp(Real1 ra, float br, Binary ab) {
private static Real1 binaryOp(Real1 ra, float br, Binary ab) { Sampling sa = ra.getSampling(); Sampling sc = sa; Real1 rc = new Real1(sc); float[] va = ra.getValues(); float[] vc = rc.getValues(); ab.apply(vc.length,va,0,br,vc,0); return rc; } private interface Binary {
void assertEquals(Real1 e, Real1 a) { Sampling se = e.getSampling(); Sampling sa = a.getSampling(); assertTrue(sa.isEquivalentTo(se)); float[] ve = e.getValues(); float[] va = a.getValues(); int n = ve.length; for (int i=0; i<n; ++i) assertEquals(ve[i],va[i],TINY); } }
/** * Convolves this function with the specified function. The two functions * must be uniformly sampled with equal sampling intervals. * @param ra the function with which to convolve. * @return the convolution function. */ public Real1 convolve(Real1 ra) { Real1 rx = this; Real1 ry = ra; Sampling sx = rx.getSampling(); Sampling sy = ry.getSampling(); double dx = sx.getDelta(); double dy = sy.getDelta(); Check.state(sx.isUniform(),"sampling is uniform"); Check.argument(sy.isUniform(),"sampling is uniform"); Check.argument(dx==dy,"sampling intervals are equal"); int lx = sx.getCount(); int ly = sy.getCount(); double fx = sx.getFirst(); double fy = sy.getFirst(); float[] x = rx.getValues(); float[] y = ry.getValues(); int lz = lx+ly-1; double dz = dx; double fz = fx+fy; float[] z = new float[lz]; Conv.conv(lx,0,x,ly,0,y,lz,0,z); return new Real1(lz,dz,fz,z); }
public void testResample() { Real1 ra = FILL1; Sampling sa = ra.getSampling(); int n1 = sa.getCount(); double d1 = sa.getDelta(); int m1 = n1/3; Sampling sb = sa.shift(-m1*d1); Real1 rb = ra.resample(sb); float[] vb = rb.getValues(); for (int i1=0; i1<m1; ++i1) assertEquals(0.0,vb[i1],0.0); for (int i1=m1; i1<n1; ++i1) assertEquals(1.0,vb[i1],0.0); Sampling sc = sa.shift(m1*d1); Real1 rc = ra.resample(sc); float[] vc = rc.getValues(); for (int i1=0; i1<n1-m1; ++i1) assertEquals(1.0,vc[i1],0.0); for (int i1=n1-m1; i1<n1; ++i1) assertEquals(0.0,vc[i1],0.0); }