1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: freq_filt.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>freq_filt.h</h1><a href="freq__filt_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00029"></a>00029 <span class="preprocessor">#ifndef FREQ_FILT_H</span> |
---|
67 | <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define FREQ_FILT_H</span> |
---|
68 | <a name="l00031"></a>00031 <span class="preprocessor"></span> |
---|
69 | <a name="l00032"></a>00032 <span class="preprocessor">#include <<a class="code" href="vec_8h.html" title="Templated Vector Class Definitions.">itpp/base/vec.h</a>></span> |
---|
70 | <a name="l00033"></a>00033 <span class="preprocessor">#include <<a class="code" href="converters_8h.html" title="Definitions of converters between different vector and matrix types.">itpp/base/converters.h</a>></span> |
---|
71 | <a name="l00034"></a>00034 <span class="preprocessor">#include <<a class="code" href="elem__math_8h.html" title="Elementary mathematical functions - header file.">itpp/base/math/elem_math.h</a>></span> |
---|
72 | <a name="l00035"></a>00035 <span class="preprocessor">#include <<a class="code" href="matfunc_8h.html" title="Various functions on vectors and matrices - header file.">itpp/base/matfunc.h</a>></span> |
---|
73 | <a name="l00036"></a>00036 <span class="preprocessor">#include <<a class="code" href="specmat_8h.html" title="Definitions of special vectors and matrices.">itpp/base/specmat.h</a>></span> |
---|
74 | <a name="l00037"></a>00037 <span class="preprocessor">#include <<a class="code" href="min__max_8h.html" title="Minimum and maximum functions on vectors and matrices.">itpp/base/math/min_max.h</a>></span> |
---|
75 | <a name="l00038"></a>00038 |
---|
76 | <a name="l00039"></a>00039 |
---|
77 | <a name="l00040"></a>00040 <span class="keyword">namespace </span>itpp |
---|
78 | <a name="l00041"></a>00041 { |
---|
79 | <a name="l00042"></a>00042 |
---|
80 | <a name="l00108"></a>00108 <span class="keyword">template</span><<span class="keyword">class</span> Num_T> |
---|
81 | <a name="l00109"></a><a class="code" href="classitpp_1_1Freq__Filt.html">00109</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1Freq__Filt.html" title="Freq_Filt Frequency domain filtering using the overlap-add techniqueThe Freq_Filt...">Freq_Filt</a> |
---|
82 | <a name="l00110"></a>00110 { |
---|
83 | <a name="l00111"></a>00111 <span class="keyword">public</span>: |
---|
84 | <a name="l00118"></a><a class="code" href="classitpp_1_1Freq__Filt.html#566f4527e6d0703a69bc0c18f8ad5965">00118</a> <a class="code" href="classitpp_1_1Freq__Filt.html#566f4527e6d0703a69bc0c18f8ad5965" title="Constructor.">Freq_Filt</a>() {} |
---|
85 | <a name="l00119"></a>00119 |
---|
86 | <a name="l00131"></a><a class="code" href="classitpp_1_1Freq__Filt.html#1d0d4feca98ec7f8886ba2f300e33c1f">00131</a> <a class="code" href="classitpp_1_1Freq__Filt.html#1d0d4feca98ec7f8886ba2f300e33c1f" title="Constructor with initialization of the impulse response b.">Freq_Filt</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> &b, <span class="keyword">const</span> <span class="keywordtype">int</span> xlength) {init(b, xlength);} |
---|
87 | <a name="l00132"></a>00132 |
---|
88 | <a name="l00142"></a>00142 <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> <a class="code" href="classitpp_1_1Freq__Filt.html#5415257117e474e62813333df29e1058" title="Filter data in the input vector x.">filter</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> &x, <span class="keyword">const</span> <span class="keywordtype">int</span> strm = 0); |
---|
89 | <a name="l00143"></a>00143 |
---|
90 | <a name="l00145"></a><a class="code" href="classitpp_1_1Freq__Filt.html#2067b82ebe9adeea1aa01837efe0e994">00145</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Freq__Filt.html#2067b82ebe9adeea1aa01837efe0e994" title="Return FFT size.">get_fft_size</a>() { <span class="keywordflow">return</span> fftsize; } |
---|
91 | <a name="l00146"></a>00146 |
---|
92 | <a name="l00148"></a><a class="code" href="classitpp_1_1Freq__Filt.html#09167ad3fd01177e833a6aa92ebe8544">00148</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Freq__Filt.html#09167ad3fd01177e833a6aa92ebe8544" title="Return the data block size.">get_blk_size</a>() { <span class="keywordflow">return</span> blksize; } |
---|
93 | <a name="l00149"></a>00149 |
---|
94 | <a name="l00151"></a><a class="code" href="classitpp_1_1Freq__Filt.html#76d3952d1a349fa2a1c5fbc9248e5318">00151</a> <a class="code" href="classitpp_1_1Freq__Filt.html#76d3952d1a349fa2a1c5fbc9248e5318" title="Destructor.">~Freq_Filt</a>() {} |
---|
95 | <a name="l00152"></a>00152 |
---|
96 | <a name="l00153"></a>00153 <span class="keyword">private</span>: |
---|
97 | <a name="l00154"></a>00154 <span class="keywordtype">int</span> fftsize, blksize; |
---|
98 | <a name="l00155"></a>00155 cvec B; <span class="comment">// FFT of impulse vector</span> |
---|
99 | <a name="l00156"></a>00156 <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> impulse; |
---|
100 | <a name="l00157"></a>00157 <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> old_data; |
---|
101 | <a name="l00158"></a>00158 cvec zfinal; |
---|
102 | <a name="l00159"></a>00159 |
---|
103 | <a name="l00160"></a>00160 <span class="keywordtype">void</span> init(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> &b, <span class="keyword">const</span> <span class="keywordtype">int</span> xlength); |
---|
104 | <a name="l00161"></a>00161 vec overlap_add(<span class="keyword">const</span> vec &x); |
---|
105 | <a name="l00162"></a>00162 svec overlap_add(<span class="keyword">const</span> svec &x); |
---|
106 | <a name="l00163"></a>00163 ivec overlap_add(<span class="keyword">const</span> ivec &x); |
---|
107 | <a name="l00164"></a>00164 cvec overlap_add(<span class="keyword">const</span> cvec &x); |
---|
108 | <a name="l00165"></a>00165 <span class="keywordtype">void</span> overlap_add(<span class="keyword">const</span> cvec &x, cvec &y); |
---|
109 | <a name="l00166"></a>00166 }; |
---|
110 | <a name="l00167"></a>00167 |
---|
111 | <a name="l00168"></a>00168 |
---|
112 | <a name="l00169"></a>00169 <span class="comment">// Initialize impulse rsponse, FFT size and block size</span> |
---|
113 | <a name="l00170"></a>00170 <span class="keyword">template</span> <<span class="keyword">class</span> Num_T> |
---|
114 | <a name="l00171"></a>00171 <span class="keywordtype">void</span> Freq_Filt<Num_T>::init(<span class="keyword">const</span> Vec<Num_T> &b, <span class="keyword">const</span> <span class="keywordtype">int</span> xlength) |
---|
115 | <a name="l00172"></a>00172 { |
---|
116 | <a name="l00173"></a>00173 <span class="comment">// Set the impulse response</span> |
---|
117 | <a name="l00174"></a>00174 impulse = b; |
---|
118 | <a name="l00175"></a>00175 |
---|
119 | <a name="l00176"></a>00176 <span class="comment">// Get the length of the impulse response</span> |
---|
120 | <a name="l00177"></a>00177 <span class="keywordtype">int</span> num_elements = impulse.length(); |
---|
121 | <a name="l00178"></a>00178 |
---|
122 | <a name="l00179"></a>00179 <span class="comment">// Initizlize old data</span> |
---|
123 | <a name="l00180"></a>00180 old_data.set_size(0, <span class="keyword">false</span>); |
---|
124 | <a name="l00181"></a>00181 |
---|
125 | <a name="l00182"></a>00182 <span class="comment">// Initialize the final state</span> |
---|
126 | <a name="l00183"></a>00183 zfinal.set_size(num_elements - 1, <span class="keyword">false</span>); |
---|
127 | <a name="l00184"></a>00184 zfinal.zeros(); |
---|
128 | <a name="l00185"></a>00185 |
---|
129 | <a name="l00186"></a>00186 vec Lvec; |
---|
130 | <a name="l00187"></a>00187 |
---|
131 | <a name="l00188"></a>00188 <span class="comment">/*</span> |
---|
132 | <a name="l00189"></a>00189 <span class="comment"> * Compute the FFT size and the data block size to use.</span> |
---|
133 | <a name="l00190"></a>00190 <span class="comment"> * The FFT size is N = L + M -1, where L corresponds to</span> |
---|
134 | <a name="l00191"></a>00191 <span class="comment"> * the block size (to be determined) and M corresponds</span> |
---|
135 | <a name="l00192"></a>00192 <span class="comment"> * to the impulse length. The method used here is designed</span> |
---|
136 | <a name="l00193"></a>00193 <span class="comment"> * to minimize the (number of blocks) * (number of flops per FFT)</span> |
---|
137 | <a name="l00194"></a>00194 <span class="comment"> * Use the FFTW flop computation of 5*N*log2(N).</span> |
---|
138 | <a name="l00195"></a>00195 <span class="comment"> */</span> |
---|
139 | <a name="l00196"></a>00196 vec n = <a class="code" href="group__specmat.html#ge5632baa525e231b015f3d45f3503cac" title="Linspace (works in the same way as the matlab version).">linspace</a>(1, 20, 20); |
---|
140 | <a name="l00197"></a>00197 n = <a class="code" href="group__logexpfunc.html#g40f48a75172e7f8bc8e58ed54262a04d" title="Calculates x to the power of y (x^y).">pow</a>(2.0, n); |
---|
141 | <a name="l00198"></a>00198 ivec fftflops = <a class="code" href="group__convertfunc.html#ga2c82af9774f45c3554fb03a06f3e28d" title="Converts an int to ivec.">to_ivec</a>(elem_mult(5.0 * n, <a class="code" href="group__logexpfunc.html#gd50278d885a02a1448976186bb4ad5cd" title="log-2 of the elements">log2</a>(n))); |
---|
142 | <a name="l00199"></a>00199 |
---|
143 | <a name="l00200"></a>00200 <span class="comment">// Find where the FFT sizes are > (num_elements-1)</span> |
---|
144 | <a name="l00201"></a>00201 <span class="comment">//ivec index = find(n,">", static_cast<double>(num_elements-1));</span> |
---|
145 | <a name="l00202"></a>00202 ivec index(n.length()); |
---|
146 | <a name="l00203"></a>00203 <span class="keywordtype">int</span> cnt = 0; |
---|
147 | <a name="l00204"></a>00204 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ii = 0; ii < n.length(); ii++) { |
---|
148 | <a name="l00205"></a>00205 <span class="keywordflow">if</span> (n(ii) > (num_elements - 1)) { |
---|
149 | <a name="l00206"></a>00206 index(cnt) = ii; |
---|
150 | <a name="l00207"></a>00207 cnt += 1; |
---|
151 | <a name="l00208"></a>00208 } |
---|
152 | <a name="l00209"></a>00209 } |
---|
153 | <a name="l00210"></a>00210 index.set_size(cnt, <span class="keyword">true</span>); |
---|
154 | <a name="l00211"></a>00211 |
---|
155 | <a name="l00212"></a>00212 fftflops = fftflops(index); |
---|
156 | <a name="l00213"></a>00213 n = n(index); |
---|
157 | <a name="l00214"></a>00214 |
---|
158 | <a name="l00215"></a>00215 <span class="comment">// Minimize number of blocks * number of flops per FFT</span> |
---|
159 | <a name="l00216"></a>00216 Lvec = n - (double)(num_elements - 1); |
---|
160 | <a name="l00217"></a>00217 <span class="keywordtype">int</span> min_ind = <a class="code" href="group__miscfunc.html#g30831e540d60212e23437cc259253f2f" title="Return the postion of the minimum element in the matrix.">min_index</a>(elem_mult(<a class="code" href="group__convertfunc.html#g0cb0ca1ce1f1218522ba2b1e0e1fe5a5" title="Round to nearest upper integer.">ceil</a>((<span class="keywordtype">double</span>)xlength / Lvec), <a class="code" href="group__fixed.html#g9e5d027084a2a9e65500a0f5d4cf81a8" title="Converts a fixvec to vec.">to_vec</a>(fftflops))); |
---|
161 | <a name="l00218"></a>00218 fftsize = <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(n(min_ind)); |
---|
162 | <a name="l00219"></a>00219 blksize = <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(Lvec(min_ind)); |
---|
163 | <a name="l00220"></a>00220 |
---|
164 | <a name="l00221"></a>00221 <span class="comment">// Finally, compute the FFT of the impulse response</span> |
---|
165 | <a name="l00222"></a>00222 B = <a class="code" href="group__fft.html#g47b556fc383bceb3cc562045acfa9f00" title="Fast Fourier Transform, with zero-padding up to size N.">fft</a>(<a class="code" href="group__fixed.html#g3f0aa27746b5d5880f77e96c089498f2" title="Converts a cfixvec to cvec.">to_cvec</a>(impulse), fftsize); |
---|
166 | <a name="l00223"></a>00223 } |
---|
167 | <a name="l00224"></a>00224 |
---|
168 | <a name="l00225"></a>00225 <span class="comment">// Filter data</span> |
---|
169 | <a name="l00226"></a>00226 <span class="keyword">template</span> <<span class="keyword">class</span> Num_T> |
---|
170 | <a name="l00227"></a><a class="code" href="classitpp_1_1Freq__Filt.html#5415257117e474e62813333df29e1058">00227</a> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> <a class="code" href="classitpp_1_1Freq__Filt.html#5415257117e474e62813333df29e1058" title="Filter data in the input vector x.">Freq_Filt<Num_T>::filter</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> &input, <span class="keyword">const</span> <span class="keywordtype">int</span> strm) |
---|
171 | <a name="l00228"></a>00228 { |
---|
172 | <a name="l00229"></a>00229 <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> x, tempv; |
---|
173 | <a name="l00230"></a>00230 <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec<Num_T></a> output; |
---|
174 | <a name="l00231"></a>00231 |
---|
175 | <a name="l00232"></a>00232 <span class="comment">/*</span> |
---|
176 | <a name="l00233"></a>00233 <span class="comment"> * If we are not in streaming mode we want to process all of the data.</span> |
---|
177 | <a name="l00234"></a>00234 <span class="comment"> * However, if we are in streaming mode we want to process the data in</span> |
---|
178 | <a name="l00235"></a>00235 <span class="comment"> * blocks that are commensurate with the designed 'blksize' parameter.</span> |
---|
179 | <a name="l00236"></a>00236 <span class="comment"> * So, we do a little book keeping to divide the iinput vector into the</span> |
---|
180 | <a name="l00237"></a>00237 <span class="comment"> * correct size.</span> |
---|
181 | <a name="l00238"></a>00238 <span class="comment"> */</span> |
---|
182 | <a name="l00239"></a>00239 <span class="keywordflow">if</span> (!strm) { |
---|
183 | <a name="l00240"></a>00240 x = input; |
---|
184 | <a name="l00241"></a>00241 zfinal.zeros(); |
---|
185 | <a name="l00242"></a>00242 old_data.set_size(0, <span class="keyword">false</span>); |
---|
186 | <a name="l00243"></a>00243 } |
---|
187 | <a name="l00244"></a>00244 <span class="keywordflow">else</span> { <span class="comment">// we aare in streaming mode</span> |
---|
188 | <a name="l00245"></a>00245 tempv = concat(old_data, input); |
---|
189 | <a name="l00246"></a>00246 <span class="keywordflow">if</span> (tempv.<a class="code" href="classitpp_1_1Vec.html#44478ea086eda22a180102e77e352325" title="The size of the vector.">length</a>() <= blksize) { |
---|
190 | <a name="l00247"></a>00247 x = tempv; |
---|
191 | <a name="l00248"></a>00248 old_data.set_size(0, <span class="keyword">false</span>); |
---|
192 | <a name="l00249"></a>00249 } |
---|
193 | <a name="l00250"></a>00250 <span class="keywordflow">else</span> { |
---|
194 | <a name="l00251"></a>00251 <span class="keywordtype">int</span> end = tempv.<a class="code" href="classitpp_1_1Vec.html#44478ea086eda22a180102e77e352325" title="The size of the vector.">length</a>(); |
---|
195 | <a name="l00252"></a>00252 <span class="keywordtype">int</span> numblks = end / blksize; |
---|
196 | <a name="l00253"></a>00253 <span class="keywordflow">if</span> ((end % blksize)) { |
---|
197 | <a name="l00254"></a>00254 x = tempv(0, blksize * numblks - 1); |
---|
198 | <a name="l00255"></a>00255 old_data = tempv(blksize * numblks, end - 1); |
---|
199 | <a name="l00256"></a>00256 } |
---|
200 | <a name="l00257"></a>00257 <span class="keywordflow">else</span> { |
---|
201 | <a name="l00258"></a>00258 x = tempv(0, blksize * numblks - 1); |
---|
202 | <a name="l00259"></a>00259 old_data.set_size(0, <span class="keyword">false</span>); |
---|
203 | <a name="l00260"></a>00260 } |
---|
204 | <a name="l00261"></a>00261 } |
---|
205 | <a name="l00262"></a>00262 } |
---|
206 | <a name="l00263"></a>00263 output = overlap_add(x); |
---|
207 | <a name="l00264"></a>00264 |
---|
208 | <a name="l00265"></a>00265 <span class="keywordflow">return</span> output; |
---|
209 | <a name="l00266"></a>00266 } |
---|
210 | <a name="l00267"></a>00267 |
---|
211 | <a name="l00268"></a>00268 } <span class="comment">// namespace itpp</span> |
---|
212 | <a name="l00269"></a>00269 |
---|
213 | <a name="l00270"></a>00270 <span class="preprocessor">#endif // #ifndef FREQ_FILT_H</span> |
---|
214 | </pre></div></div> |
---|
215 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:11 2009 for mixpp by |
---|
216 | <a href="http://www.doxygen.org/index.html"> |
---|
217 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
218 | </body> |
---|
219 | </html> |
---|