void CIIRfilter::lowpass(complex *p, char *ptype, int np, double *sn, double *sd, int *ns )
{
	int	iptr, i;
        *ns = 0;
        iptr = 0;
	for (i = 0; i < np; i++)
	{
		if (    ptype[i] == 'C' )
		{
			sn[iptr]     = 1.;
			sn[iptr + 1] = 0.;
			sn[iptr + 2] = 0.;
			sd[iptr] = real_part(cmplx_mul(p[i],cmplx_conjg(p[i])));
			sd[iptr + 1] = -2. * real_part( p[i] );
			sd[iptr + 2] = 1.;
			iptr = iptr + 3;
			*ns = *ns + 1;
		}
		else if (  ptype[i] == 'S' )
		{
			sn[ iptr ]     = 1.;
			sn[ iptr + 1 ] = 0.;
			sn[ iptr + 2 ] = 0.;
			sd[ iptr ]     = -real_part( p[i] );
			sd[ iptr + 1 ] = 1.;
			sd[ iptr + 2 ] = 0.;
			iptr = iptr + 3;
			
			*ns = *ns + 1;
		}
	}
}
void CIIRfilter::lp_to_hp(complex p[], char ptype[], int np, double sn[], double sd[], int *ns )
	{
	int	i, iptr;
        *ns = 0;
        iptr = 0;
	for (i = 0; i < np; i++)
		{
		if (ptype[i] == 'C' )
			{
			sn[ iptr ]     = 0.f;
			sn[ iptr + 1 ] = 0.f;
			sn[ iptr + 2 ] = 1.f;
			sd[ iptr ]     = 1.f;
			sd[ iptr + 1 ] = -2.f * real_part( p[i] );
			sd[ iptr + 2 ] = real_part(cmplx_mul(p[i], cmplx_conjg(p[i])));
			iptr = iptr + 3;
			*ns = *ns + 1;
			}
		else if (  ptype[i] == 'S' )
			{
			sn[ iptr ]     = 0.;
			sn[ iptr + 1 ] = 1.;
			sn[ iptr + 2 ] = 0.;
			sd[ iptr ]     = 1.;
			sd[ iptr + 1 ] = -real_part( p[i] );
			sd[ iptr + 2 ] = 0.;
			iptr = iptr + 3;
			*ns = *ns + 1;
			}
		}
}
void CIIRfilter::lp_to_bp( complex *p, char *ptype, int np, double fl, double fh,
			  double *sn, double *sd, int *ns )
	{
	complex	ctemp, p1, p2;
	double	pi, twopi, a, b;
	int	i, iptr;
        pi = M_PI;
        twopi = 2.*pi;
        a = twopi*twopi*fl*fh;
        b = twopi*( fh - fl );
        *ns = 0;
        iptr = 0;
	for (i = 0; i < np; i++)
	{
		if (    ptype[i] == 'C' )
		{
			ctemp = real_cmplx_mul(b, p[i]);
			ctemp = cmplx_mul(ctemp, ctemp);
			ctemp = cmplx_sub(ctemp, cmplx(4.*a, 0.));
			ctemp = cmplx_sqrt( ctemp );
			p1 = real_cmplx_mul(0.5, 
				cmplx_add(real_cmplx_mul(b,p[i]), ctemp));
			p2 = real_cmplx_mul(0.5, 
				cmplx_sub(real_cmplx_mul(b,p[i]), ctemp));
			sn[ iptr ]     = 0.;
			sn[ iptr + 1 ] = b;
			sn[ iptr + 2 ] = 0.;
			sd[iptr] = real_part(cmplx_mul(p1, cmplx_conjg(p1)));
			sd[ iptr + 1 ] = -2. * real_part( p1 );
			sd[ iptr + 2 ] = 1.;
			iptr = iptr + 3;
			sn[ iptr ]     = 0.;
			sn[ iptr + 1 ] = b;
			sn[ iptr + 2 ] = 0.;
			sd[iptr] = real_part(cmplx_mul(p2, cmplx_conjg(p2)));
			sd[ iptr + 1 ] = -2. * real_part( p2 );
			sd[ iptr + 2 ] = 1.;
			iptr = iptr + 3;
			*ns = *ns + 2;
		}
		else if ( ptype[i] == 'S' )
		{
			sn[ iptr ]     = 0.;
			sn[ iptr + 1 ] = b;
			sn[ iptr + 2 ] = 0.;
			sd[ iptr ]     = a;
			sd[ iptr + 1 ] = -b*real_part( p[i] );
			sd[ iptr + 2 ] = 1.;
			iptr = iptr + 3;
			*ns = *ns + 1;
		}
	}
}
Пример #4
0
static Lisp_Object pluscc(Lisp_Object a, Lisp_Object b)
/*
 * Add complex values.
 */
{
    Lisp_Object c, nil;
    push2(a, b);
    c = plus2(imag_part(a), imag_part(b));
    pop2(b, a);
    errexit();
    a = plus2(real_part(a), real_part(b));
    errexit();
    return make_complex(a, c);
}
Пример #5
0
int main(void)
{
  const double pi = 3.1415926;
  struct complex_struct z1 = make_from_real_img(2, 4),
                        z2 = make_from_mag_ang(10, pi / 4);
  
  printf("z1:\nreal_part = %f\nimg_part = %f\nmagnitude = %f\nangle = %f\n",
          real_part(z1), img_part(z1), magnitude(z1), angle(z1));
  printf("\n\n");
  printf("z2:\nreal_part = %f\nimg_part = %f\nmagnitude = %f\nangle = %f\n",
          real_part(z2), img_part(z2), magnitude(z2), angle(z2));
  
  return 0;
}
Пример #6
0
Lisp_Object make_complex(Lisp_Object r, Lisp_Object i)
{
    Lisp_Object v, nil = C_nil;
/*
 * Here r and i are expected to be either both rational (which in this
 * context includes the case of integer values) or both of the same
 * floating point type.  It is assumed that this has already been
 * arranged by here.
 */
    if (i == fixnum_of_int(0)) return r;
    stackcheck2(0, r, i);
    push2(r, i);
    v = getvector(TAG_NUMBERS, TYPE_COMPLEX_NUM, sizeof(Complex_Number));
/*
 * The vector r has uninitialized contents here - dodgy.  If the call
 * to getvector succeeded then I fill it in, otherwise I will not
 * refer to it again, and I think that unreferenced vectors containing junk
 * are OK.
 */
    pop2(i, r);
    errexit();
    real_part(v) = r;
    imag_part(v) = i;
    return v;
}
Пример #7
0
static Lisp_Object Lrealpart(Lisp_Object nil, Lisp_Object a)
{
    CSL_IGNORE(nil);
    if (!is_number(a)) return aerror1("realpart", a);
    if (is_numbers(a) && is_complex(a))
        return onevalue(real_part(a));
    else return onevalue(a);
}
Пример #8
0
int main()
{
    COMPLEX_FLOAT f = 1.0f + _Complex_I;

    float r1 = real_part(f);
    float r2 = real_part_2(f);

    return r1 - r2;
}
Пример #9
0
// If x is real then Re(e).diff(x) is equal to Re(e.diff(x)) 
static ex real_part_expl_derivative(const ex & arg, const symbol & s)
{
	if (s.info(info_flags::real))
		return real_part_function(arg.diff(s));
	else {
		exvector vec_arg;
		vec_arg.push_back(arg);
		return fderivative(ex_to<function>(real_part(arg)).get_serial(),0,vec_arg).hold()*arg.diff(s);
	}
}
Пример #10
0
static Lisp_Object plusic(Lisp_Object a, Lisp_Object b)
/*
 * real of any sort plus complex.
 */
{
    Lisp_Object nil;
    push(b);
    a = plus2(a, real_part(b));
    pop(b);
    errexit();
/*
 * make_complex() takes responsibility for mapping #C(n 0) onto n
 */
    return make_complex(a, imag_part(b));
}
Пример #11
0
static Lisp_Object Lconjugate(Lisp_Object nil, Lisp_Object a)
{
    if (!is_number(a)) return aerror1("conjugate", a);
    if (is_numbers(a) && is_complex(a))
    {   Lisp_Object r = real_part(a),
                    i = imag_part(a);
        push(r);
        i = negate(i);
        pop(r);
        errexit();
        a = make_complex(r, i);
        errexit();
        return onevalue(a);
    }
    else return onevalue(a);
}
        void register_abs_entry( size_type const ug_index, value_type const ug_value, value_type progress_ratio )
        {
            size_type const m = ug_size;
            matrix_type real_part(m, 1);
            matrix_type imag_part(m, 1);

            std::fill( real_part.begin(), real_part.end(), value_type{} );
            std::fill( imag_part.begin(), imag_part.end(), value_type{} );

            value_type const weigh = ( value_type{1} - progress_ratio ) * std::sqrt( static_cast<value_type>(m) );
            value_type const intensity = value_type{2} * weigh * ug_value * weigh * ug_value;

            real_part[ug_index][0] = weigh;
            imag_part[ug_index][0] = weigh;

            dsm.register_entry( intensity, real_part.begin(), imag_part.begin() );
        }
Пример #13
0
CSLbool onep(Lisp_Object a)
{
    switch ((int)a & TAG_BITS)
    {
    case TAG_FIXNUM:
        return (a == fixnum_of_int(1));
    case TAG_NUMBERS:
        /* #C(r i) must satisfy onep(r) and zerop(i) */
        if (is_complex(a) && onep(real_part(a)))
            return zerop(imag_part(a));
        else return NO;
    case TAG_SFLOAT:
    {   Float_union w;
        w.f = (float)1.0;
        return (a == (w.i & ~(int32_t)0xf) + TAG_SFLOAT);
    }
    case TAG_BOXFLOAT:
        return (float_of_number(a) == 1.0);
    default:
        return NO;
    }
}
Пример #14
0
CSLbool zerop(Lisp_Object a)
{
    switch ((int)a & TAG_BITS)
    {
    case TAG_FIXNUM:
        return (a == fixnum_of_int(0));
    case TAG_NUMBERS:
        /* #C(r i) must satisfy zerop is r and i both do */
        if (is_complex(a) && zerop(real_part(a)))
            return zerop(imag_part(a));
        else return NO;
    case TAG_SFLOAT:
        /*
         * The code here assumes that the the floating point number zero
         * is represented by a zero bit-pattern... see onep() for a more
         * cautious way of coding things.
         */
        return ((a & 0x7ffffff8) == 0); /* Strip sign bit as well as tags */
    case TAG_BOXFLOAT:
        return (float_of_number(a) == 0.0);
    default:
        return NO;
    }
}
        void register_entry(    size_matrix_type const& ar, 
                                value_type alpha, complex_matrix_type const& lhs_matrix, complex_matrix_type const& rhs_matrix, 
                                value_type beta, complex_matrix_type const& expm_matrix, 
                                matrix_type const& intensity, size_type const column_index = 0 )
        {
            assert( ar.row() == ar.col() );
            assert( ar.row() == lhs_matrix.row() );
            assert( lhs_matrix.row() == lhs_matrix.col() );
            assert( ar.row() == rhs_matrix.row() );
            assert( ar.row() == intensity.row() );
            assert( 1 == intensity.col() );
            assert( (*(std::max_element(ar.begin(), ar.end()))) < ug_size );
            assert( alpha >= value_type{0} );
            assert( beta >= value_type{0} );
            assert( alpha <= value_type{1} );
            assert( beta <= value_type{1} );
            assert( std::abs(alpha+beta-value_type{1}) < value_type{ 1.0e-10} );
            //assert( c1_matrix.row() == ar.row() );
            //assert( c1_matrix.col() == 1 );
            assert( expm_matrix.row() == ar.row() );
            assert( expm_matrix.col() == 1 );
            assert( column_index < ar.row() );

            size_type const n = ar.row();
            size_type const m = ug_size;

            matrix_type real_part(m, 1);
            matrix_type imag_part(m, 1);

            value_type norm_factor{0};
            //norm only one column
            //std::for_each( expm_matrix.col_begin( column_index ), expm_matrix.col_end( column_index ), [&norm_factor]( complex_type const& c ){ norm_factor += std::norm(c); } );
            std::for_each( expm_matrix.begin(), expm_matrix.end(), [&norm_factor]( complex_type const& c ){ norm_factor += std::norm(c); } );
            norm_factor /= static_cast<value_type>( expm_matrix.row() );

            for ( size_type r = 0; r != ar.row(); ++r )
            {
                //for \beta C/2 C/2 part
                extract_inner_product_coefficients( m, n, ar.row_begin(r), lhs_matrix.row_begin(r), rhs_matrix.col_begin(column_index), real_part.begin(), imag_part.begin() );
                real_part *= alpha;
                imag_part *= alpha;

                //for \gamma E part
                real_part[0][0] += beta * std::real( expm_matrix[r][column_index] );
                imag_part[0][0] += beta * std::imag( expm_matrix[r][column_index] );
                //real_part[0][0] += beta * std::real( expm_matrix[r][column_index] ) / norm_factor;
                //imag_part[0][0] += beta * std::imag( expm_matrix[r][column_index] ) / norm_factor;

                //needs modifying here
                dsm.register_entry( intensity[r][0], real_part.begin(), imag_part.begin() );
            }

#if 0
            //register lambda, ensuring lambda to be 1
            std::fill( real_part.begin(), real_part.end(), value_type{} );
            value_type const factor = value_type{1.0};
            value_type const weigh = factor * std::sqrt( static_cast<value_type>( intensity.row() ) );
            real_part[0][0] = weigh;
            imag_part[0][0] = weigh;
            dsm.register_entry( value_type{2} * weigh * weigh, real_part.begin(), imag_part.begin() );
#endif
        }
Пример #16
0
static CSLbool numeqic(Lisp_Object a, Lisp_Object b)
{
    if (!zerop(imag_part(b))) return NO;
    else return numeq2(a, real_part(b));
}
Пример #17
0
static CSLbool numeqcc(Lisp_Object a, Lisp_Object b)
{
    return numeq2(real_part(a), real_part(b)) &&
           numeq2(imag_part(a), imag_part(b));
}
Пример #18
0
//---------------------------------------------------------------------------------------------------
complex add_complex(complex a, complex b){
    return make_from_real_img(real_part(a)+real_part(b), img_part(a)+img_part(b));
}
Пример #19
0
complex minus_complex(complex a, complex b){
    return make_from_real_img(real_part(a)-real_part(b), img_part(a)-img_part(b));
}
Пример #20
0
Lisp_Object negate(Lisp_Object a)
{
#ifdef COMMON
    Lisp_Object nil;  /* needed for errexit() */
#endif
    switch ((int)a & TAG_BITS)
    {
case TAG_FIXNUM:
        {   int32_t aa = -int_of_fixnum(a);
/*
 * negating the number -#x8000000 (which is a fixnum) yields a value
 * which just fails to be a fixnum.
 */
            if (aa != 0x08000000) return fixnum_of_int(aa);
            else return make_one_word_bignum(aa);
        }
#ifdef COMMON
case TAG_SFLOAT:
        {   Float_union aa;
            aa.i = a - TAG_SFLOAT;
            aa.f = (float) (-aa.f);
            return (aa.i & ~(int32_t)0xf) + TAG_SFLOAT;
        }
#endif
case TAG_NUMBERS:
        {   int32_t ha = type_of_header(numhdr(a));
            switch (ha)
            {
    case TYPE_BIGNUM:
                return negateb(a);
#ifdef COMMON
    case TYPE_RATNUM:
                {   Lisp_Object n = numerator(a),
                                d = denominator(a);
                    push(d);
                    n = negate(n);
                    pop(d);
                    errexit();
                    return make_ratio(n, d);
                }
    case TYPE_COMPLEX_NUM:
                {   Lisp_Object r = real_part(a),
                                i = imag_part(a);
                    push(i);
                    r = negate(r);
                    pop(i);
                    errexit();
                    push(r);
                    i = negate(i);
                    pop(r);
                    errexit();
                    return make_complex(r, i);
                }
#endif
    default:
                return aerror1("bad arg for minus",  a);
            }
        }
case TAG_BOXFLOAT:
        {   double d = float_of_number(a);
            return make_boxfloat(-d, type_of_header(flthdr(a)));
        }
default:
        return aerror1("bad arg for minus",  a);
    }
}
Пример #21
0
boost::multi_array<double, DIMENSION>
get_real_parts(const boost::multi_array<SCALAR, DIMENSION> &data) {
  boost::multi_array<double, DIMENSION> real_part(data.shape());
  std::transform(data.begin(), data.end(), real_part.begin(), get_real);
  return real_part;
};