📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
double dd = 0;
double dataR[128];
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double kk[3], ll;
double vref[3];
double ph[3];
ph[0] = 1;
ph[1] = this->phb->Text.ToDouble();
ph[2] = this->phc->Text.ToDouble();
vref[0] = this->voltagea->Text.ToDouble()*sqrt(2);
vref[1] = this->voltageb->Text.ToDouble()*sqrt(2);
vref[2] = this->voltagec->Text.ToDouble()*sqrt(2);
this->Chart1->Series[0]->Clear();
for( Byte xx = 0; xx < 128; xx++ )
{
ll = sin( 314.15926 * xx / 6400 );
ll = vref[0] * ll + vref[1] * sin( 314.15926 * ph[1]*xx / 6400) + vref[2] * sin( 314.15926 * ph[2]*xx / 6400 );
dataR[xx] = ll;
}
for( Byte xx = 0; xx < 128; xx++ )
{
this->Chart1->Series[0]->Add( dataR[xx] ,AnsiString(xx+1),this->Chart1->Series[0]->SeriesColor);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
double TR,TI,dataI[128],temp,w[32];
Byte x0,x1,x2,x3,x4,x5,x6,i,xx;
int L,j,k,b,p;
double sin_tab[64],cos_tab[64];
for(k = 0; k < 64; k++)
{
cos_tab[k] = cos(2*3.1415926/128*k);
sin_tab[k] = sin(-(2*3.1415926/128*k));
}
for(i=0;i<128;i++)
{
x0=x1=x2=x3=x4=x5=0;
x0=i&0x01; x1=(i/2)&0x01; x2=(i/4)&0x01; x3=(i/8)&0x01;
x4=(i/16)&0x01; x5=(i/32)&0x01, x6 = (i/64)&0x01;
xx=x0*64+x1*32+x2*16+x3*8+x4*4+x5*2+x6;
dataI[xx]=dataR[i];
}
for(i=0;i<128;i++)
{
dataR[i]=dataI[i];
dataI[i]=0;
}
//************** following code FFT *******************
for(L=1;L<=7;L++) //for(1)
{
b=1;
i=L-1;
while(i>0)
{
b=b*2;
i--;
} // b= 2^(L-1)
for(j=0;j<=b-1;j++) // for (2)
{
p=1;
i=7-L;
while(i>0) // p=pow(2,7-L)*j;
{
p=p*2;
i--;
}
p=p*j;
for(k=j;k<128;k=k+2*b) // for (3)
{
TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
} // END for (3)
} // END for (2)
} // END for (1)
this->ListBox1->Clear();
for(i=0;i<32;i++)
{ // 只需要32次以下的谐波进行分析
w[i]=sqrt((dataR[i]*dataR[i]+dataI[i]*dataI[i])*2);
w[i]=w[i]/128;
}
w[0]=w[0]/2;
for(i= 1; i<32; i++)
{
String tt = "第"+AnsiString(i)+"次谐波= ";
tt = tt + tt.FormatFloat("0.0000",w[i]) +"V";
this->ListBox1->Items->Add(tt);
}
this->ListBox1->ItemIndex = 0;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -