1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Example Documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.18 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="examples.html">Examples</a> </center>
<hr><h1>realFFTExample.cc</h1> This is an example of how to use the class. It transforms a sine tone stored in the .dat file and saves the in, out, and power_spectrum results of using the class
<p>
<div class="fragment"><pre><span class="comment">/* Copyright 2001,2002 Matt Flax <flatmax@ieee.org></span>
<span class="comment"> This file is part of the MFFM FFTw Wrapper library.</span>
<span class="comment"></span>
<span class="comment"> MFFM MFFM FFTw Wrapper library is free software; you can </span>
<span class="comment"> redistribute it and/or modify</span>
<span class="comment"> it under the terms of the GNU General Public License as published by</span>
<span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
<span class="comment"> (at your option) any later version.</span>
<span class="comment"> </span>
<span class="comment"> MFFM FFTw Wrapper library is distributed in the hope that it will be useful,</span>
<span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="comment"> GNU General Public License for more details.</span>
<span class="comment"> </span>
<span class="comment"> You have received a copy of the GNU General Public License</span>
<span class="comment"> along with the MFFM FFTw Wrapper library</span>
<span class="comment">*/</span>
<span class="preprocessor">#include <fstream></span>
<span class="preprocessor">#include <iomanip></span>
<span class="preprocessor">#include <mffm/realFFT.H></span>
<span class="preprocessor">#define INPUTFILE "sine.1000Hz.dat"</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE "powerSpectrum.txt"</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE1 "in.txt"</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE2 "out.txt"</span>
<span class="preprocessor"></span>
<span class="keywordtype">int</span> main (<span class="keywordtype">void</span>){
ifstream input(INPUTFILE);
ofstream output(OUTPUTFILE);
ofstream output1(OUTPUTFILE1);
ofstream output2(OUTPUTFILE2);
<span class="keywordtype">int</span> count=0;
<span class="keywordtype">double</span> var;
<span class="comment">// Get the file size and check file exists ....</span>
<span class="keywordflow">if</span> (!input){
cout <<<span class="stringliteral">"input not opened !"</span><<endl;
exit(-1);
}
<span class="keywordflow">while</span> (input >> var)
count++;
<span class="comment">//input.close();</span>
cout<<count<<<span class="stringliteral">" variables in file "</span><<INPUTFILE<<endl;
<span class="comment">//input.open(INPUTFILE);</span>
input.clear();
input.seekg(0);
<a name="_a0"></a><a class="code" href="classrealFFTData.html">realFFTData</a> fftData(count);
<a name="_a1"></a><a class="code" href="classrealFFT.html">realFFT</a> rfft(&fftData);
<span class="comment">// read data into data and rdata :</span>
<span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<count; i++)
input >> fftData.<a name="a2"></a><a class="code" href="classrealFFTData.html#m3">in</a>[i];
input.close();
<span class="comment">// forward transform :</span>
rfft.<a name="a3"></a><a class="code" href="classrealFFT.html#a4">fwdTransform</a>();
<span class="comment">// Find the power spectrum ...</span>
fftData.<a name="a4"></a><a class="code" href="classrealFFTData.html#a8">compPowerSpec</a>();
<span class="comment">/*</span>
<span class="comment"> // inverse transform to check what happens (have to rescale too): </span>
<span class="comment"> rfft.invTransform();</span>
<span class="comment"> */</span>
<span class="comment">// output to file :</span>
<span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<(count+1)/2; i++){
output << fftData.<a name="a5"></a><a class="code" href="classrealFFTData.html#m5">power_spectrum</a>[i]<<<span class="charliteral">'\n'</span>;
}
<span class="comment">// cout <<(count+1)/2<<endl;</span>
output.close();
<span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<count; i++){
output1 << fftData.<a class="code" href="classrealFFTData.html#m3">in</a>[i]<<<span class="charliteral">'\n'</span>;
output2 << fftData.<a name="a6"></a><a class="code" href="classrealFFTData.html#m4">out</a>[i]<<<span class="charliteral">'\n'</span>;
}
output1.close();
output2.close();
<span class="keywordflow">return</span> 0;
}
</pre></div><hr><address style="align: right;"><small>Generated on Thu Jun 19 11:21:56 2003 for MFFM FFTw Wrapper by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.18 </small></address>
</body>
</html>
|