File: realFFTExample_8cc-example.html

package info (click to toggle)
mffm-fftw 1.7-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,768 kB
  • sloc: cpp: 711; makefile: 76
file content (113 lines) | stat: -rw-r--r-- 6,862 bytes parent folder | download | duplicates (5)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MFFM FFTw Wrapper: realFFTExample.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>realFFTExample.cc</h1><p>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 class="fragment"><span class="comment">/* Copyright 2001,2002 Matt Flax &lt;flatmax@ieee.org&gt;</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 &lt;fstream&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="keyword">using namespace </span>std;

<span class="preprocessor">#include &lt;mffm/realFFT.H&gt;</span>
<span class="preprocessor">#include &lt;stdlib.h&gt;</span>

<span class="preprocessor">#define INPUTFILE &quot;sine.1000Hz.dat&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE &quot;powerSpectrum.txt&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE1 &quot;in.txt&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define OUTPUTFILE2 &quot;out.txt&quot;</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 &lt;&lt;<span class="stringliteral">&quot;input not opened !&quot;</span>&lt;&lt;endl;
    exit(-1);
  }
  <span class="keywordflow">while</span> (input &gt;&gt; var)
    count++;
  <span class="comment">//input.close();</span>
  
  cout&lt;&lt;count&lt;&lt;<span class="stringliteral">&quot; variables in file &quot;</span>&lt;&lt;INPUTFILE&lt;&lt;endl;

  <span class="comment">//input.open(INPUTFILE);</span>
  input.clear();
  input.seekg(0);
 
  <a name="_a0"></a><a class="code" href="classrealFFTData.html" title="class realFFTData controls and manipulates fft data">realFFTData</a> fftData(count);
  <a name="_a1"></a><a class="code" href="classrealFFT.html" title="class realFFT controls fftw plans and executes fwd/inv transforms">realFFT</a> rfft(&amp;fftData);

  <span class="comment">// read data into data and rdata :</span>
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;count; i++)
    input &gt;&gt; fftData.<a name="a2"></a><a class="code" href="classrealFFTData.html#a2bf1dadc9fd55d2b1bc5371027c4ac8a" title="the input, output and power_spectrum arrays">in</a>[i];
  input.close();

  <span class="comment">// forward transform :</span>
  rfft.<a name="a3"></a><a class="code" href="classrealFFT.html#ac41a7dcecd3246a439a31f59cf8e266f" title="Forward transform the data (in to out).">fwdTransform</a>();

  <span class="comment">// Find the power spectrum ...</span>
  fftData.<a name="a4"></a><a class="code" href="classrealFFTData.html#a304eac736338b0c7c0bb990ab14d4399" title="This function computes the power spectrum and returns the max bin.">compPowerSpec</a>();
  
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;count; i++)
    fftData.<a class="code" href="classrealFFTData.html#a2bf1dadc9fd55d2b1bc5371027c4ac8a" title="the input, output and power_spectrum arrays">in</a>[i]=0.0;
  <span class="comment">// inverse transform to check what happens (have to rescale too): </span>
  rfft.<a name="a5"></a><a class="code" href="classrealFFT.html#a0d8793bbdca4f51cfc063e6b35c524ec" title="Inverse transform the data (out to in).">invTransform</a>();
  
  <span class="comment">// output to file :</span>
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;(count+1)/2; i++){
    output &lt;&lt; fftData.<a name="a6"></a>power_spectrum[i]&lt;&lt;<span class="charliteral">&apos;\n&apos;</span>;
  }
  <span class="comment">//  cout &lt;&lt;(count+1)/2&lt;&lt;endl;</span>
  output.close();

  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;count; i++){
    output1 &lt;&lt; fftData.<a class="code" href="classrealFFTData.html#a2bf1dadc9fd55d2b1bc5371027c4ac8a" title="the input, output and power_spectrum arrays">in</a>[i]/count&lt;&lt;<span class="charliteral">&apos;\n&apos;</span>;
    output2 &lt;&lt; fftData.<a name="a7"></a>out[i]&lt;&lt;<span class="charliteral">&apos;\n&apos;</span>;
  }
  output1.close();
  output2.close();
  <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Thu Dec 17 00:32:35 2009 for MFFM FFTw Wrapper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>