home *** CD-ROM | disk | FTP | other *** search
- # include <math.h>
- # include <graph.h>
- # include <stdlib.h>
- # include <stdio.h>
- # include "miscio.h"
- # include "fft.h"
- # include "worlddr.h"
- # include "segraph.h"
-
- float xdata[128], ydata[128], xcopy[128], ycopy[128], tdata[128];
- int code,lower,upper,n,i,j,k,window;
- char ch, chstr[2] = {0,0};
- float pi = 3.14159;
- extern BlackAndWhite;
-
-
- void main(){
- n = 128;
- for ( i= 0; i <= n-1; i++) {
- xdata[i] = 6 * cos(pi*i/(19.0 + (rand()/32767.0)))
- + 3.5 *cos(pi*i/12.0 ) +
- 3.0 * sin(pi*i/4) + 7*(rand()/32767.0)
- *sin(pi*i/(8.0+(rand()/32767.0)));
- ydata[i] = 0;
- tdata[i] = i;
- }
- ClrScr();
- InitSEGraphics(6);
- do{
- SetCurrentWindow(10);
- ClearWindow();
- BorderCurrentWindow(10);
- LabelGraphWindow(100,900,"FFT Window Options ( 0-5 ): ",0,0);
- LabelGraphWindow(100,800,"0 - Rectangular ",0,0);
- LabelGraphWindow(100,700,"1 - Parzen ",0,0);
- LabelGraphWindow(100,600,"2 - Hanning ",0,0);
- LabelGraphWindow(100,500,"3 - Welch ",0,0);
- LabelGraphWindow(100,400,"4 - Hamming ",0,0);
- LabelGraphWindow(100,300,"5 - Exact Blackman ",0,0);
- LabelGraphWindow(100,200,"6 - Exit ",0,0);
- LabelGraphWindow(100,100,"Enter Selection ? ",0,0);
- ch = getch();
-
- chstr[0] = ch;
- LabelGraphWindow(6000,100,chstr,0,0);
- window = ch-48;
- CopyVectors( xdata,n, xcopy);
- CopyVectors( ydata,n, ycopy );
- if (window <6) {
- SetCurrentWindow(7);
- ClearWindow();
- if (BlackAndWhite == 0)
- SetViewBackground(14);
- SetAxesType(0,0);
- SelectColor(2);
- AutoAxes(tdata,xcopy,n,0);
- LinePlotData(tdata, xcopy, n,1, 0);
- SelectColor(3);
- TitleWindow("Raw Signal Data");
- setlinestyleXX(1,0,1);
- DrawGrid(10);
- setlinestyleXX(0,0,1);
- BorderCurrentWindow(1);
- WindowFFTData(xcopy,ycopy,n,window);
-
- SetCurrentWindow(8);
- ClearWindow();
- if (BlackAndWhite == 0)
- SetViewBackground(12);
- SetAxesType(0,0);
- SelectColor(2);
- AutoAxes(tdata,xcopy,n,0);
- LinePlotData(tdata, xcopy, n,1, 0);
- SelectColor(3);
- switch (window) {
- case 0 : TitleWindow( "Signal X Rectangular Window"); break;
- case 1 : TitleWindow( "Signal X Parzen Window"); break;
- case 2 : TitleWindow( "Signal X Hanning Window"); break;
- case 3 : TitleWindow( "Signal X Welch Window"); break;
- case 4 : TitleWindow( "Signal X Hamming Window "); break;
- case 5 : TitleWindow( "Signal X Exact Blackman Window"); break;
- }
- BorderCurrentWindow(window+1);
-
- PowerSpectrumCalc(xcopy,ycopy,n,0.01);
- SetCurrentWindow(9);
- ClearWindow();
- if (BlackAndWhite == 0)
- SetViewBackground(3);
- SelectColor(1);
- SetAxesType(0,0);
- xcopy[31] = 2.0;
- AutoAxes(ycopy,xcopy,n / 2,0);
- LinePlotData(ycopy, xcopy, n / 2 - 1,5, 0);
- TitleWindow("Power Spectrum");
- TitleXAxis("Frequency");
- TitleYAxis("Power Density");
- BorderCurrentWindow(9);
- }
- }
- while ( window < 6);
- CloseSEGraphics();
- }
-
-
-