中国科学技术大学电子工程与信息科学系多媒体通信实验室(版权所有2000 )。
基于附录A C语言的数字信号处理算法实现
附录A1 BC中多种类型的实现
您可以在http 3360//3/DSP/c/complex use.CPP上找到此部分。
1、使用BC提供的多种支持
//BC中使用多类型的示例(Complex Use.Cpp文件) ) ) ) ) ) ) ) )。
#包含
#包含
输入主(语音) )。
{
双精度x=3.1,y=4.2;
complexz=complex(x,y );
cout 'z=' z 'n ';
cout ' andimaginaryrealpart=' imag (z ) 'n ';
cout ' zhascomplexconjugate=' conj (z ) 'n ';
返回0;
}
2、定义多个类,填写相应的成员函数
//C中的多类型调用可能不起作用,但可以自己定义多类型(Complex Use.Cpp文件) )。
class Complex{
公共:
Complex () }
完成(浮动re、浮动im );
float r () {return real; (;
float i () {return imag; (;
浮动模式()返回sqrt ) real*realimag*imag ); (;
完成操作器(完成操作器;
完成操作器- ()完成操作器;
complexoperator*(complexother;
完成操作器/(完成操作器;
隐私:
浮动实际、imag;
(; //operatoroverloadedusingamemberfunction
complex :3360 complex (浮动re,浮动im ) {
如果在阅读的过程中发现遗漏或错误,请尽快联系编辑。 网络@ cxh @
中国科学技术大学电子工程与信息科学系多媒体通信实验室(版权所有2000 )。
real=re;
imag=im;
(;
complex complex :3360操作器(complex other )。
返回完成(realother.real,imag other.imag );
(;
complex complex :3360操作器- (complex other )。
返回完成(real-other.real,imag - other.imag );
(;
complex complex :3360 operator * { complex other }
浮动x,y;
x=real * other.real-imag * other.imag;
y=real * other.imag imag * other.real;
返回完成(x,y );
(;
complex complex :3360操作器/(complex other )。
浮动x、y、l;
l=other.real * other.realother.imag * other.imag;
x=real * other.real imag * other.imag;
y=other.real * imag-real * other.imag;
x=x/l;
y=y/l;
返回完成(x