/** * Returns a sampled function with values zero. * @param s the sampling. * @return the function. */ public static Real1 zero(Sampling s) { return new Real1(s); }
/** * Returns a function with constant values. * @param ar the constant. * @param s the sampling. * @return the function. */ public static Real1 fill(double ar, Sampling s) { int n = s.getCount(); return new Real1(s, fillfloat((float)ar,n)); }
/** * Returns a sampled function with values zero. * @param n the number of samples. * @return the function. */ public static Real1 zero(int n) { return new Real1(new Sampling(n)); }
private Real1 computeImpulseResponse() { // Arrays of poles and zeros. int np = _poles.size(); int nz = _zeros.size(); Cdouble[] poles = new Cdouble[np]; Cdouble[] zeros = new Cdouble[nz]; _poles.toArray(poles); _zeros.toArray(zeros); // Array for impulse response h. int n = 101; float[] h = new float[n]; // If at least one pole or zero, then construct and apply the filter. // Otherwise, the impulse response is simply an impulse. if (np>0 || nz>0) { float[] impulse = new float[n]; impulse[0] = 1.0f; RecursiveCascadeFilter f = new RecursiveCascadeFilter(poles,zeros,1.0); f.applyForward(impulse,h); } else { h[0] = 1.0f; } Sampling s = new Sampling(n); return new Real1(s,h); }
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 {
int is = overlap[2]; Real1 rt = this; Real1 rs = new Real1(s); float[] xt = rt.getValues(); float[] xs = rs.getValues();
/** * Returns a sampled linear (ramp) function. * The function values are fv+dv*(s-f), for s = f, f+d, ..., f+d*(n-1), * where n, d, and f are the sampling count, delta, and first value. * @param fv the first function value. * @param dv the function value delta. * @param s the sampling. * @return the function. */ public static Real1 ramp(double fv, double dv, Sampling s) { int n = s.getCount(); double d = s.getDelta(); double f = s.getFirst(); return new Real1(s, rampfloat((float)(fv-f*dv),(float)(d*dv),n)); }
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) {
/** * 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); }