home *** CD-ROM | disk | FTP | other *** search
- /*===========================================================
- Please note, that the program FFT uses the unit RChart,
- which is not supplied with the FOURIER package. If you
- don't have it, you can download the shareware version from
- one of the following WWW sites:
- http://qspr03.tuwien.ac.at/lo/
- http://www.lohninger.com/
- ===========================================================*/
-
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "frmfft.h"
- #include "math.h"
- //---------------------------------------------------------------------------
- #pragma link "Fourier"
- #pragma link "RChart"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::StartFFT()
- {
- int i;
- double y;
- double pmax;
-
- RChart1->ClearGraf();
- RChart1->DataColor = clBlue;
- RChart1->MoveTo (0,0);
- FFT1->ClearImag();
- for (i=1; i<=FFT1->SpectrumSize; i++)
- {
- y = 10*(sin(0.01*i*(100-SBFreq1->Position))+sin(0.075*i)+cos(0.5*i)+
- 0.06*(random(100-ScrollBar1->Position)-0.5*(100-ScrollBar1->Position)));
- FFT1->RealSpec[i] = y; // real value
- RChart1->DrawTo (i,y);
- }
- RChart1->ShowGraf();
-
- FFT1->Transform();
-
- RChart2->ClearGraf();
- RChart2->DataColor = clRed;
- pmax = FFT1->PowerMax;
- if (pmax > 0)
- {
- RChart2->MoveTo (2,FFT1->PowerSpec[2]/pmax);
- for (i=2; i<=FFT1->SpectrumSize; i++)
- {
- y = FFT1->PowerSpec[i]/pmax;
- RChart2->DrawTo (i,y);
- }
- }
- RChart2->ShowGraf();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::BButExitClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::CBoxWindChange(TObject *Sender)
- {
- if (CBoxWind->Text == "Rectangle")
- {
- FFT1->WeightingWindow = fwRectangle;
- }
- if (CBoxWind->Text == "Triangle")
- {
- FFT1->WeightingWindow = fwTriangle;
- }
- if (CBoxWind->Text == "Gaussian")
- {
- FFT1->WeightingWindow = fwGauss;
- }
- if (CBoxWind->Text == "Hamming")
- {
- FFT1->WeightingWindow = fwHamming;
- }
- if (CBoxWind->Text == "Blackman")
- {
- FFT1->WeightingWindow = fwBlackman;
- }
- if (CBoxWind->Text == "cos2")
- {
- FFT1->WeightingWindow = fwCos2;
- }
- StartFFT();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
- {
- StartFFT();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SBFreq1Change(TObject *Sender)
- {
- StartFFT();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormActivate(TObject *Sender)
- {
- CBoxWind->Text = "None";
- StartFFT();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::CBLogYClick(TObject *Sender)
- {
- RChart2->LogScaleY = CBLogY->Checked;
- if (RChart2->LogScaleY)
- {
- RChart2->DecPlaceY = -1;
- }
- else
- {
- RChart2->DecPlaceY = 2;
- }
- }
- //---------------------------------------------------------------------------