- メインページ
- モジュール
- ネームスペース
- データ構造
- ファイル

- ファイル一覧
- グローバル

window_function.h
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
29 #ifndef __INCLUDE_MIST_WINDOW_FUNCTION_H__
30 #define __INCLUDE_MIST_WINDOW_FUNCTION_H__
31
32
33 #ifndef __INCLUDE_MIST_H__
34 #include "../mist.h"
35 #endif
36
37 #include <cmath>
38
39 _MIST_BEGIN
40
41
42 namespace window_function
43 {
48 template < typename T, class Allocator >
49 inline void hamming( const array1< T, Allocator > &in, array1< T, Allocator > &out )
50 {
51 out.resize( in.size( ) );
52
53 size_t length = in.size( );
54
55 for( size_t i = 0 ; i < length ; i++ )
56 {
57 double x = static_cast< double >( i ) / static_cast< double >( length );
58 out[ i ] = in[ i ] * ( 0.54 - 0.46 * cos( 2.0 * 3.141592 * x ) );
59 }
60 }
61
62
67 template < typename T, class Allocator >
68 inline void blackman( const array1< T, Allocator > &in, array1< T, Allocator > &out )
69 {
70 out.resize( in.size( ) );
71
72 size_t length = in.size( );
73
74 for( size_t i = 0 ; i < length ; i++ )
75 {
76 double x = static_cast< double >( i ) / static_cast< double >( length );
77 out[ i ] = in[ i ] * ( 0.42 - 0.5 * cos( 2.0 * 3.141592 * x ) + 0.08 * cos( 4.0 * 3.141592 * x ) );
78 }
79 }
80
81
86 template < typename T, class Allocator >
87 inline void hann( const array1< T, Allocator > &in, array1< T, Allocator > &out )
88 {
89 out.resize( in.size( ) );
90
91 size_t length = in.size( );
92
93 for( size_t i = 0 ; i < length ; i++ )
94 {
95 double x = static_cast< double >( i ) / static_cast< double >( length );
96 out[ i ] = in[ i ] * ( 0.5 - 0.5 * cos( 2.0 * 3.141592 * x ) );
97 }
98 }
99
100 } // namespace window_function
101
102
103 _MIST_END
104
105
106 #endif
107