home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / matemat / Vyssi / FOURIER.ZIP / exmpl-1 / cpp / frmfft.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.3 KB  |  124 lines

  1. /*===========================================================
  2.  Please note, that the program FFT uses the unit RChart,
  3.  which is not supplied with the FOURIER package. If you
  4.  don't have it, you can download the shareware version from
  5.  one of the following WWW sites:
  6.      http://qspr03.tuwien.ac.at/lo/
  7.      http://www.lohninger.com/
  8.  ===========================================================*/
  9.  
  10. #include <vcl\vcl.h>
  11. #pragma hdrstop
  12.  
  13. #include "frmfft.h"
  14. #include "math.h"
  15. //---------------------------------------------------------------------------
  16. #pragma link "Fourier"
  17. #pragma link "RChart"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22.     : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::StartFFT()
  27. {
  28. int      i;
  29. double     y;
  30. double     pmax;
  31.  
  32. RChart1->ClearGraf();
  33. RChart1->DataColor = clBlue;
  34. RChart1->MoveTo (0,0);
  35. FFT1->ClearImag();
  36. for (i=1; i<=FFT1->SpectrumSize; i++)
  37.   {
  38.   y = 10*(sin(0.01*i*(100-SBFreq1->Position))+sin(0.075*i)+cos(0.5*i)+
  39.        0.06*(random(100-ScrollBar1->Position)-0.5*(100-ScrollBar1->Position)));
  40.   FFT1->RealSpec[i] = y;           // real value
  41.   RChart1->DrawTo (i,y);
  42.   }
  43. RChart1->ShowGraf();
  44.  
  45. FFT1->Transform();
  46.  
  47. RChart2->ClearGraf();
  48. RChart2->DataColor = clRed;
  49. pmax = FFT1->PowerMax;
  50. if (pmax > 0) 
  51.   {
  52.   RChart2->MoveTo (2,FFT1->PowerSpec[2]/pmax);
  53.   for (i=2; i<=FFT1->SpectrumSize; i++)
  54.     {
  55.     y = FFT1->PowerSpec[i]/pmax;
  56.     RChart2->DrawTo (i,y);
  57.     }
  58.   }
  59. RChart2->ShowGraf();
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TForm1::BButExitClick(TObject *Sender)
  63. {
  64. Close();    
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::CBoxWindChange(TObject *Sender)
  68. {
  69. if (CBoxWind->Text == "Rectangle")
  70.   {
  71.   FFT1->WeightingWindow = fwRectangle;
  72.   }
  73. if (CBoxWind->Text == "Triangle")
  74.   {
  75.   FFT1->WeightingWindow = fwTriangle;
  76.   }
  77. if (CBoxWind->Text == "Gaussian")
  78.   {
  79.   FFT1->WeightingWindow = fwGauss;
  80.   }
  81. if (CBoxWind->Text == "Hamming")
  82.   {
  83.   FFT1->WeightingWindow = fwHamming;
  84.   }
  85. if (CBoxWind->Text == "Blackman")
  86.   {
  87.   FFT1->WeightingWindow = fwBlackman;
  88.   }
  89. if (CBoxWind->Text == "cos2")
  90.   {
  91.   FFT1->WeightingWindow = fwCos2;
  92.   }
  93. StartFFT();
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
  97. {
  98. StartFFT();    
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TForm1::SBFreq1Change(TObject *Sender)
  102. {
  103. StartFFT();    
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TForm1::FormActivate(TObject *Sender)
  107. {
  108. CBoxWind->Text = "None";
  109. StartFFT();
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TForm1::CBLogYClick(TObject *Sender)
  113. {
  114. RChart2->LogScaleY = CBLogY->Checked;
  115. if (RChart2->LogScaleY)
  116.   {
  117.   RChart2->DecPlaceY = -1;
  118.   }
  119. else
  120.   {
  121.   RChart2->DecPlaceY = 2;
  122.   }
  123. }
  124. //---------------------------------------------------------------------------