blib/lib/Math/FFT.pm

filter: Statementstmt 2.9% 11 / 374 Branchbran 0.0% 0 / 176 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 12.9% 4 / 31 Podpod n/a totaltotal 2.3% 15 / 642 CC 117 SCAR 54.9
CC
117
Cov
2%
spctrm
992.0
correl
90.0
deconvlv
90.0
CRAP 241.6
↑ Summary Build »
1 package Math::FFT;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 require DynaLoader;
10  
11 @ISA = qw(DynaLoader);
12  
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16 our $VERSION = '1.35';
17  
18 bootstrap Math::FFT $VERSION;
19  
20 # Preloaded methods go here.
21  
22 sub new
23 {
24 0 ▶ my ( $class, $data ) = @_;
Subroutine new: not called CC=3 SCAR=24.8
25 0 ▶ die 'Must call constructor with an array reference for the data'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
26 unless ref($data) eq 'ARRAY';
27 0 ▶ $data->[0] ||= 0; # keep warnings happy
Condition0%0/2
$data->[0] ||= 0
l!l
00
MC/DC0%0/1
$data->[0] ||= 0
$data->[0]
Truth table0%0/2
A
A= $data->[0]
Aresult
11
00
28 0 my $n = @$data;
29 0 my $nip = int( 3 + sqrt($n) );
30 0 my $nw = int( 2 + 5 * $n / 4 );
31 0 my $ip = pack( "i$nip", () );
32 0 my $w = pack( "d$nw", () );
33 0 return bless {
34 type => '',
35 mean => '',
36 coeff => '',
37 n => $n,
38 data => $data,
39 ip => \$ip,
40 w => \$w,
41 }, $class;
42 }
43  
44 # clone method to copy the ip and w arrays for data of equal size
45 sub clone
46 {
47 0 ▶ my ( $self, $data ) = @_;
Subroutine clone: not called CC=4 SCAR=30.0
48 0 ▶ die 'Must call clone with an array reference for the data'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
49 unless ref($data) eq 'ARRAY';
50 0 ▶ $data->[0] ||= 0; # keep warnings happy
Condition0%0/2
$data->[0] ||= 0
l!l
00
MC/DC0%0/1
$data->[0] ||= 0
$data->[0]
Truth table0%0/2
A
A= $data->[0]
Aresult
11
00
51 0 my $n = @$data;
52 0 ▶ die "Cannot clone data of unequal sizes" unless $n == $self->{n};
Branch: 1 branch
BranchTrueFalseTotal
unless $n == $self->{"n"} 0 0 0
53 0 my $class = ref($self);
54 return bless {
55 type => '',
56 coeff => '',
57 mean => '',
58 n => $self->{n},
59 data => $data,
60 ip => $self->{ip},
61 w => $self->{w},
62 0 }, $class;
63 }
64  
65 # Complex Discrete Fourier Transform
66 sub cdft
67 {
68 0 ▶ my $self = shift;
Subroutine cdft: not called CC=2 SCAR=17.9
69 0 my $n = $self->{n};
70 0 ▶ die "data size ($n) must be an integer power of 2" unless _check_n($n);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
71 0 my $data = [ @{ $self->{data} } ];
72 0 _cdft( $n, 1, $data, $self->{ip}, $self->{w} );
73 0 $self->{type} = 'cdft';
74 0 $self->{coeff} = $data;
75 0 return $data;
76 }
77  
78 # Inverse Complex Discrete Fourier Transform
79 sub invcdft
80 {
81 0 ▶ my $self = shift;
Subroutine invcdft: not called CC=6 SCAR=37.4
82 0 my $data;
83 0 my $n = $self->{n};
84 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
85 {
86 0 ▶ if ( ref($arg) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg ne "ARRAY") 0 0 0
87 {
88 0 die 'Must pass an array reference to invcdft';
89 }
90 0 ▶ if ( $n != @$arg )
Branch: 1 branch
BranchTrueFalseTotal
if ($n != @$arg) 0 0 0
91 {
92 0 die "Size of data set must be $n";
93 }
94 0 $data = [@$arg];
95 }
96 else
97 {
98 die 'Must invert data created with cdft'
99 0 ▶ unless $self->{type} eq 'cdft';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "cdft" 0 0 0
100 0 $data = [ @{ $self->{coeff} } ];
101 }
102 0 _cdft( $n, -1, $data, $self->{ip}, $self->{w} );
103 0 $_ *= 2.0 / $n for (@$data);
104 0 return $data;
105 }
106  
107 # Real Discrete Fourier Transform
108 sub rdft
109 {
110 0 ▶ my $self = shift;
Subroutine rdft: not called CC=2 SCAR=17.9
111 0 my $n = $self->{n};
112 0 ▶ if ( !_check_n($n) )
Branch: 1 branch
BranchTrueFalseTotal
unless (_check_n($n)) 0 0 0
113 {
114 0 die "data size ($n) must be an integer power of 2";
115 }
116 0 my $data = [ @{ $self->{data} } ];
117 0 _rdft( $n, 1, $data, $self->{ip}, $self->{w} );
118 0 $self->{type} = 'rdft';
119 0 $self->{coeff} = $data;
120 0 return $data;
121 }
122  
123 # Inverse Real Discrete Fourier Transform
124 sub invrdft
125 {
126 0 ▶ my $self = shift;
Subroutine invrdft: not called CC=6 SCAR=37.4
127 0 my $data;
128 0 my $n = $self->{n};
129 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
130 {
131 0 ▶ die 'Must pass an array reference to invrdft'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
132 unless ref($arg) eq 'ARRAY';
133 0 ▶ die "Size of data set must be $n"
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @$arg 0 0 0
134 unless $n == @$arg;
135 0 $data = [@$arg];
136 }
137 else
138 {
139 die 'Must invert data created with rdft'
140 0 ▶ unless $self->{type} eq 'rdft';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "rdft" 0 0 0
141 0 $data = [ @{ $self->{coeff} } ];
142 }
143 0 _rdft( $n, -1, $data, $self->{ip}, $self->{w} );
144 0 $_ *= 2.0 / $n for (@$data);
145 0 return $data;
146 }
147  
148 # Discrete Cosine Transform
149 sub ddct
150 {
151 0 ▶ my $self = shift;
Subroutine ddct: not called CC=2 SCAR=17.9
152 0 my $n = $self->{n};
153 0 ▶ die "data size ($n) must be an integer power of 2" unless _check_n($n);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
154 0 my $data = [ @{ $self->{data} } ];
155 0 _ddct( $n, -1, $data, $self->{ip}, $self->{w} );
156 0 $self->{type} = 'ddct';
157 0 $self->{coeff} = $data;
158 0 return $data;
159 }
160  
161 # Inverse Discrete Cosine Transform
162 sub invddct
163 {
164 0 ▶ my $self = shift;
Subroutine invddct: not called CC=6 SCAR=37.4
165 0 my $data;
166 0 my $n = $self->{n};
167 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
168 {
169 0 ▶ die 'Must pass an array reference to invddct'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
170 unless ref($arg) eq 'ARRAY';
171 0 ▶ die "Size of data set must be $n"
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @$arg 0 0 0
172 unless $n == @$arg;
173 0 $data = [@$arg];
174 }
175 else
176 {
177 die 'Must invert data created with ddct'
178 0 ▶ unless $self->{type} eq 'ddct';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "ddct" 0 0 0
179 0 $data = [ @{ $self->{coeff} } ];
180 }
181 0 $data->[0] *= 0.5;
182 0 _ddct( $n, 1, $data, $self->{ip}, $self->{w} );
183 0 $_ *= 2.0 / $n for (@$data);
184 0 return $data;
185 }
186  
187 # Discrete Sine Transform
188 sub ddst
189 {
190 0 ▶ my $self = shift;
Subroutine ddst: not called CC=2 SCAR=17.9
191 0 my $n = $self->{n};
192 0 ▶ die "data size ($n) must be an integer power of 2" unless _check_n($n);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
193 0 my $data = [ @{ $self->{data} } ];
194 0 _ddst( $n, -1, $data, $self->{ip}, $self->{w} );
195 0 $self->{type} = 'ddst';
196 0 $self->{coeff} = $data;
197 0 return $data;
198 }
199  
200 # Inverse Discrete Sine Transform
201 sub invddst
202 {
203 0 ▶ my $self = shift;
Subroutine invddst: not called CC=6 SCAR=37.4
204 0 my $data;
205 0 my $n = $self->{n};
206 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
207 {
208 0 ▶ die 'Must pass an array reference to invddst'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
209 unless ref($arg) eq 'ARRAY';
210 0 ▶ die "Size of data set must be $n"
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @$arg 0 0 0
211 unless $n == @$arg;
212 0 $data = [@$arg];
213 }
214 else
215 {
216 die 'Must invert data created with ddst'
217 0 ▶ unless $self->{type} eq 'ddst';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "ddst" 0 0 0
218 0 $data = [ @{ $self->{coeff} } ];
219 }
220 0 $data->[0] *= 0.5;
221 0 _ddst( $n, 1, $data, $self->{ip}, $self->{w} );
222 0 $_ *= 2.0 / $n for (@$data);
223 0 return $data;
224 }
225  
226 # Cosine Transform of RDFT (Real Symmetric DFT)
227 sub dfct
228 {
229 0 ▶ my $self = shift;
Subroutine dfct: not called CC=2 SCAR=17.9
230 0 my $np1 = $self->{n};
231 0 my $n = $np1 - 1;
232 0 ▶ die "data size ($n) must be an integer power of 2" unless _check_n($n);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
233 0 my $nt = int( 2 + $n / 2 );
234 0 my $t = [];
235 0 my $data = [ @{ $self->{data} } ];
236 0 pdfct( $nt, $n, $data, $t, $self->{ip}, $self->{w} );
237 0 $self->{type} = 'dfct';
238 0 $self->{coeff} = $data;
239 0 return $data;
240 }
241  
242 # Inverse Cosine Transform of RDFT (Real Symmetric DFT)
243 sub invdfct
244 {
245 0 ▶ my $self = shift;
Subroutine invdfct: not called CC=6 SCAR=37.4
246 0 my $data;
247 0 my $np1 = $self->{n};
248 0 my $n = $np1 - 1;
249 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
250 {
251 0 ▶ die 'Must pass an array reference to invdfct'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
252 unless ref($arg) eq 'ARRAY';
253 0 ▶ die "Size of data set must be $n"
Branch: 1 branch
BranchTrueFalseTotal
unless $np1 == @$data 0 0 0
254 unless $np1 == @$data;
255 0 $data = [@$arg];
256 }
257 else
258 {
259 die 'Must invert data created with dfct'
260 0 ▶ unless $self->{type} eq 'dfct';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "dfct" 0 0 0
261 0 $data = [ @{ $self->{coeff} } ];
262 }
263 0 my $nt = int( 2 + $n / 2 );
264 0 my $t = [];
265 0 $data->[0] *= 0.5;
266 0 $data->[$n] *= 0.5;
267 0 pdfct( $nt, $n, $data, $t, $self->{ip}, $self->{w} );
268 0 $data->[0] *= 0.5;
269 0 $data->[$n] *= 0.5;
270 0 $_ *= 2.0 / $n for (@$data);
271 0 return $data;
272 }
273  
274 # Sine Transform of RDFT (Real Anti-symmetric DFT)
275 sub dfst
276 {
277 0 ▶ my $self = shift;
Subroutine dfst: not called CC=2 SCAR=17.9
278 0 my $n = $self->{n};
279 0 ▶ die "data size ($n) must be an integer power of 2" unless _check_n($n);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
280 0 my $data = [ @{ $self->{data} } ];
281 0 my $nt = int( 2 + $n / 2 );
282 0 my $t = [];
283 0 pdfst( $nt, $n, $data, $t, $self->{ip}, $self->{w} );
284 0 $self->{type} = 'dfst';
285 0 $self->{coeff} = $data;
286 0 return $data;
287 }
288  
289 # Inverse Sine Transform of RDFT (Real Anti-symmetric DFT)
290 sub invdfst
291 {
292 0 ▶ my $self = shift;
Subroutine invdfst: not called CC=6 SCAR=37.4
293 0 my $n = $self->{n};
294 0 my $data;
295 0 ▶ if ( my $arg = shift )
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) { } 0 0 0
296 {
297 0 ▶ die 'Must pass an array reference to invdfst'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
298 unless ref($arg) eq 'ARRAY';
299 0 ▶ die "Size of data set must be $n"
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @$arg 0 0 0
300 unless $n == @$arg;
301 0 $data = [@$arg];
302 }
303 else
304 {
305 die 'Must invert data created with dfst'
306 0 ▶ unless $self->{type} eq 'dfst';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq "dfst" 0 0 0
307 0 $data = [ @{ $self->{coeff} } ];
308 }
309 0 my $nt = int( 2 + $n / 2 );
310 0 my $t = [];
311 0 pdfst( $nt, $n, $data, $t, $self->{ip}, $self->{w} );
312 0 $_ *= 2.0 / $n for (@$data);
313 0 return $data;
314 }
315  
316 # check if $n is a power of 2
317 sub _check_n
318 {
319 0 ▶ my ($n) = @_;
Subroutine _check_n: not called CC=3 SCAR=24.8
320  
321 0 ▶ return scalar( $n == int($n) and $n > 0 and ( !( $n & ( $n - 1 ) ) ) );
Condition0%0/6
$n == int $n && $n > 0 && !($n & $n - 1)
!ll&&!rl&&r
000
$n == int $n and $n > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$n == int $n && $n > 0 && !($n & $n - 1)
$n == int $n $n > 0 !($n & $n - 1)
Truth table0%0/4
A and B && not(C)
A= $n == int $nB= $n > 0C= !($n & $n - 1)
ABCresult
0XX0
10X0
1100
1111
322 }
323  
324 sub correl
325 {
326 0 ▶ my ( $self, $other ) = @_;
Subroutine correl: not called CC=9 SCAR=45.0
327 0 my $n = $self->{n};
328 my $d1 =
329 $self->{type}
330 ? (
331 $self->{type} eq 'rdft'
332 0 ▶ ? [ @{ $self->{coeff} } ]
Condition0%0/2
$self->rdft and [@{$self->{"coeff"};}]
!ll
00
MC/DC0%0/1
$self->rdft and [@{$self->{"coeff"};}]
$self->rdft
Truth table0%0/2
A
A= $self->rdft
Aresult
00
11
333 : die 'correl must involve a real function'
334 )
335 0 ▶ : $self->rdft && [ @{ $self->{coeff} } ];
Branch: 2 branches
BranchTrueFalseTotal
$self->{'type'} ? : 0 0 0
$self->{'type'} eq 'rdft' ? : 0 0 0
336 0 my $d2 = [];
337 0 ▶ if ( ref($other) eq 'Math::FFT' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $other eq 'Math::FFT') { } 0 0 0
elsif (ref $other eq 'ARRAY') { } 0 0 0
338 {
339 $d2 =
340 $other->{type}
341 ? (
342 $other->{type} eq 'rdft'
343 0 ▶ ? [ @{ $other->{coeff} } ]
Condition0%0/2
$other->rdft and [@{$other->{"coeff"};}]
!ll
00
MC/DC0%0/1
$other->rdft and [@{$other->{"coeff"};}]
$other->rdft
Truth table0%0/2
A
A= $other->rdft
Aresult
00
11
344 : die 'correl must involve a real function'
345 )
346 0 ▶ : $other->rdft && [ @{ $other->{coeff} } ];
Branch: 2 branches
BranchTrueFalseTotal
$other->{'type'} ? : 0 0 0
$other->{'type'} eq 'rdft' ? : 0 0 0
347 }
348 elsif ( ref($other) eq 'ARRAY' )
349 {
350 0 $d2 = [@$other];
351 0 _rdft( $n, 1, $d2, $self->{ip}, $self->{w} );
352 }
353 else
354 {
355 0 die 'Must call correl with either a Math::FFT object or an array ref';
356 }
357 0 my $corr = [];
358 0 _correl( $n, $corr, $d1, $d2, $self->{ip}, $self->{w} );
359 0 return $corr;
360 }
361  
362 sub convlv
363 {
364 0 ▶ my ( $self, $r ) = @_;
Subroutine convlv: not called CC=8 SCAR=42.8
365 0 ▶ die 'Must call convlv with an array reference for the response data'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "ARRAY" 0 0 0
366 unless ref($r) eq 'ARRAY';
367 0 my $respn = [@$r];
368 0 my $m = @$respn;
369 0 ▶ die 'size of response data must be an odd integer' unless $m % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $m % 2 == 1 0 0 0
370 0 my $n = $self->{n};
371 my $d1 =
372 $self->{type}
373 ? (
374 $self->{type} eq 'rdft'
375 0 ▶ ? [ @{ $self->{coeff} } ]
Condition0%0/2
$self->rdft and [@{$self->{"coeff"};}]
!ll
00
MC/DC0%0/1
$self->rdft and [@{$self->{"coeff"};}]
$self->rdft
Truth table0%0/2
A
A= $self->rdft
Aresult
00
11
376 : die 'correl must involve a real function'
377 )
378 0 ▶ : $self->rdft && [ @{ $self->{coeff} } ];
Branch: 2 branches
BranchTrueFalseTotal
$self->{'type'} ? : 0 0 0
$self->{'type'} eq 'rdft' ? : 0 0 0
379 0 ▶ for ( my $i = 1 ; $i <= ( $m - 1 ) / 2 ; ++$i )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= ($m - 1) / 2) 0 0 0
380 {
381 0 $respn->[ $n - $i ] = $respn->[ $m - $i ];
382 }
383 0 ▶ for ( my $i = ( $m + 3 ) / 2 ; $i <= $n - ( $m - 1 ) / 2 ; ++$i )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $n - ($m - 1) / 2) 0 0 0
384 {
385 0 $respn->[ $i - 1 ] = 0.0;
386 }
387 0 my $convlv = [];
388 0 _convlv( $n, $convlv, $d1, $respn, $self->{ip}, $self->{w} );
389 0 return $convlv;
390 }
391  
392 sub deconvlv
393 {
394 0 ▶ my ( $self, $r ) = @_;
Subroutine deconvlv: not called CC=9 SCAR=45.0
395 0 ▶ die 'Must call deconvlv with an array reference for the response data'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "ARRAY" 0 0 0
396 unless ref($r) eq 'ARRAY';
397 0 my $respn = [@$r];
398 0 my $m = @$respn;
399 0 ▶ die 'size of response data must be an odd integer' unless $m % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $m % 2 == 1 0 0 0
400 0 my $n = $self->{n};
401 my $d1 =
402 $self->{type}
403 ? (
404 $self->{type} eq 'rdft'
405 0 ▶ ? [ @{ $self->{coeff} } ]
Condition0%0/2
$self->rdft and [@{$self->{"coeff"};}]
!ll
00
MC/DC0%0/1
$self->rdft and [@{$self->{"coeff"};}]
$self->rdft
Truth table0%0/2
A
A= $self->rdft
Aresult
00
11
406 : die 'correl must involve a real function'
407 )
408 0 ▶ : $self->rdft && [ @{ $self->{coeff} } ];
Branch: 2 branches
BranchTrueFalseTotal
$self->{'type'} ? : 0 0 0
$self->{'type'} eq 'rdft' ? : 0 0 0
409 0 ▶ for ( my $i = 1 ; $i <= ( $m - 1 ) / 2 ; ++$i )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= ($m - 1) / 2) 0 0 0
410 {
411 0 $respn->[ $n - $i ] = $respn->[ $m - $i ];
412 }
413 0 ▶ for ( my $i = ( $m + 3 ) / 2 ; $i <= $n - ( $m - 1 ) / 2 ; ++$i )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $n - ($m - 1) / 2) 0 0 0
414 {
415 0 $respn->[ $i - 1 ] = 0.0;
416 }
417 0 my $convlv = [];
418 0 ▶ if ( _deconvlv( $n, $convlv, $d1, $respn, $self->{ip}, $self->{w} ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (_deconvlv($n, $convlv, $d1, $respn, $self->{"ip"}, $self->{"w"}) != 0) 0 0 0
419 {
420 0 die "Singularity encountered for response in deconvlv";
421 }
422 0 return $convlv;
423 }
424  
425 {
426  
427 my $PI2 = 2 * 4.0 * atan2( 1, 1 );
428  
429 sub spctrm
430 {
431 0 ▶ my ( $self, %args ) = @_;
Subroutine spctrm: not called CC=31 SCAR=69.0
432 0 my %accept = map { $_ => 1 } qw(window segments number overlap);
433 0 for ( keys %args )
434 {
435 0 ▶ die "`$_' is not a valid argument to spctrm" if not $accept{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $accept{$_} 0 0 0
436 }
437 0 my $win_fun = $args{window};
438 0 ▶ if ( $win_fun and ref($win_fun) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if ($win_fun and ref $win_fun ne "CODE") 0 0 0
Condition0%0/3
$win_fun and ref $win_fun ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$win_fun and ref $win_fun ne "CODE"
$win_fun ref $win_fun ne "CODE"
Truth table0%0/3
A and B
A= $win_funB= ref $win_fun ne "CODE"
ABresult
0X0
100
111
439 {
440 0 my %accept = map { $_ => 1 } qw(hamm hann welch bartlett);
441 die "`$win_fun' is not a known window function in spctrm"
442 0 ▶ if not $accept{$win_fun};
Branch: 1 branch
BranchTrueFalseTotal
unless $accept{$win_fun} 0 0 0
443 }
444 die 'Please specify a value for "segments" in spctrm()'
445 0 ▶ if ( $args{number} and !$args{segments} );
Branch: 1 branch
BranchTrueFalseTotal
if $args{"number"} and not $args{"segments"} 0 0 0
Condition0%0/3
$args{"number"} and not $args{"segments"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"number"} and not $args{"segments"}
$args{"number"} not $args{"segments"}
Truth table0%0/3
A and not(B)
A= $args{"number"}B= not $args{"segments"}
ABresult
0X0
100
111
446 0 my $n = $self->{n};
447 0 my $d;
448 0 my $n2 = 0;
449 0 my $spctrm = [];
450 my $win_sub = do
451 0 {
452 my $h = sub {
453 0 ▶ my ( $j, $n ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
454 0 return ( 1 - cos( $PI2 * $j / $n ) ) / 2;
455 0 };
456  
457 +{
458 'hamm' => $h,
459 'hann' => $h,
460 'welch' => sub {
461 0 ▶ my ( $j, $n ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
462 0 return 1 - 4 * ( $j - $n / 2 ) * ( $j - $n / 2 ) / $n / $n;
463 },
464 'bartlett' => sub {
465 0 ▶ my ( $j, $n ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
466 0 return 1 - abs( 2 * ( $j - $n / 2 ) / $n );
467 },
468 0 };
469 };
470 0 ▶ if ( not $args{segments}
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'segments'} or $args{'segments'} == 1 and not $args{'number'}) { } 0 0 0
Condition0%0/6
not $args{"segments"} or $args{"segments"} == 1 and not $args{"number"}
l!l&&r!l&&!r
000
$args{"segments"} == 1 and not $args{"number"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $args{"segments"} or $args{"segments"} == 1 and not $args{"number"}
not $args{"segments"} $args{"segments"} == 1 not $args{"number"}
Truth table0%0/4
not(A) or B and not(C)
A= not $args{"segments"}B= $args{"segments"} == 1C= not $args{"number"}
ABCresult
1XX1
0111
00X0
0100
471 or ( $args{segments} == 1 and not $args{number} ) )
472 {
473 0 ▶ die "data size ($n) must be an integer power of 2"
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($n) 0 0 0
474 unless _check_n($n);
475 0 ▶ if ($win_fun)
Branch: 1 branch
BranchTrueFalseTotal
if ($win_fun) { } 0 0 0
476 {
477 0 $d = [ @{ $self->{data} } ];
478 0 ▶ $win_fun = $win_sub->{$win_fun} if ref($win_fun) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $win_fun ne "CODE" 0 0 0
479 0 ▶ for ( my $j = 0 ; $j < $n ; ++$j )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $n) 0 0 0
480 {
481 0 my $w = $win_fun->( $j, $n );
482 0 $d->[$j] *= $w;
483 0 $n2 += $w * $w;
484 }
485 0 $n2 *= $n;
486 0 _spctrm( $n, $spctrm, $d, $self->{ip}, $self->{w}, $n2, 1 );
487 }
488 else
489 {
490 $d =
491 $self->{type}
492 ? (
493 $self->{type} eq 'rdft'
494 ? $self->{coeff}
495 : die 'correl must involve a real function'
496 )
497 0 ▶ : $self->rdft && $self->{coeff};
Branch: 2 branches
BranchTrueFalseTotal
$self->{'type'} ? : 0 0 0
$self->{'type'} eq 'rdft' ? : 0 0 0
Condition0%0/3
$self->rdft and $self->{"coeff"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->rdft and $self->{"coeff"}
$self->rdft $self->{"coeff"}
Truth table0%0/3
A and B
A= $self->rdftB= $self->{"coeff"}
ABresult
0X0
100
111
498 0 $n2 = $n * $n;
499 0 _spctrm( $n, $spctrm, $d, $self->{ip}, $self->{w}, $n2, 0 );
500 }
501 }
502 else
503 {
504 0 $d = [ @{ $self->{data} } ];
505 0 my ( $data, @w );
506 0 my $k = $args{segments};
507 0 my $m = $args{number};
508 0 ▶ die 'Please specify a value for "number" in spctrm()'
Branch: 1 branch
BranchTrueFalseTotal
if $k and not $m 0 0 0
Condition0%0/3
$k and not $m
!ll&&!rl&&r
000
MC/DC0%0/2
$k and not $m
$k not $m
Truth table0%0/3
A and not(B)
A= $kB= not $m
ABresult
0X0
100
111
509 if ( $k and !$m );
510 0 ▶ die "number ($m) must be an integer power of 2" unless _check_n($m);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_n($m) 0 0 0
511 0 my $m2 = $m + $m;
512 0 my $overlap = $args{overlap};
513 0 ▶ my $N = $overlap ? ( $k + 1 ) * $m : 2 * $k * $m;
Branch: 1 branch
BranchTrueFalseTotal
$overlap ? : 0 0 0
514 0 ▶ die "Need $N data points (data only has $n)" if $N > $n;
Branch: 1 branch
BranchTrueFalseTotal
if $N > $n 0 0 0
515  
516 0 ▶ if ($win_fun)
Branch: 1 branch
BranchTrueFalseTotal
if ($win_fun) { } 0 0 0
517 {
518 0 ▶ $win_fun = $win_sub->{$win_fun} if ref($win_fun) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $win_fun ne "CODE" 0 0 0
519 0 ▶ for ( my $j = 0 ; $j < $m2 ; ++$j )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $m2) 0 0 0
520 {
521 0 $w[$j] = $win_fun->( $j, $m2 );
522 0 $n2 += $w[$j] * $w[$j];
523 }
524 }
525 else
526 {
527 0 $n2 = $m2;
528 }
529 0 ▶ if ($overlap)
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap) { } 0 0 0
530 {
531 0 my @old = splice( @$d, 0, $m );
532 0 for ( 0 .. $k - 1 )
533 {
534 0 push @{ $data->[$_] }, @old;
535 0 my @new = splice( @$d, 0, $m );
536 0 push @{ $data->[$_] }, @new;
537 0 @old = @new;
538 0 ▶ if ($win_fun)
Branch: 1 branch
BranchTrueFalseTotal
if ($win_fun) 0 0 0
539 {
540 0 my $j = 0;
541 $data->[$_] =
542 0 [ map { $w[ $j++ ] * $_ } @{ $data->[$_] } ];
543 }
544 }
545 }
546 else
547 {
548 0 for ( 0 .. $k - 1 )
549 {
550 0 push @{ $data->[$_] }, splice( @$d, 0, $m2 );
551 0 ▶ if ($win_fun)
Branch: 1 branch
BranchTrueFalseTotal
if ($win_fun) 0 0 0
552 {
553 0 my $j = 0;
554 $data->[$_] =
555 0 [ map { $w[ $j++ ] * $_ } @{ $data->[$_] } ];
556 }
557 }
558 }
559 0 my $tmp = [];
560 0 my $nip = int( 3 + sqrt($m2) );
561 0 my $nw = int( 2 + 5 * $m2 / 4 );
562 0 my $ip = pack( "i$nip", () );
563 0 my $w = pack( "d$nw", () );
564 0 _spctrm_bin( $k, $m2, $spctrm, $data, \$ip, \$w, $n2, $tmp );
565 }
566 0 return $spctrm;
567 }
568 }
569  
570 sub mean
571 {
572 0 ▶ my $self = shift;
Subroutine mean: not called CC=5 SCAR=34.0
573 0 my $sum = 0;
574 0 my ( $n, $data );
575 0 my $flag = 0;
576 0 ▶ if ( $data = shift )
Branch: 1 branch
BranchTrueFalseTotal
if ($data = shift()) { } 0 0 0
577 {
578 0 ▶ die 'Must call with an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
579 unless ref($data) eq 'ARRAY';
580 0 $n = @$data;
581 0 $flag = 1;
582 }
583 else
584 {
585 0 $data = $self->{data};
586 0 $n = $self->{n};
587 }
588 0 $sum += $_ for @$data;
589 0 my $mean = $sum / $n;
590 0 ▶ $self->{mean} = $mean unless $flag == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $flag == 1 0 0 0
591 0 return $mean;
592 }
593  
594 sub rms
595 {
596 0 ▶ my $self = shift;
Subroutine rms: not called CC=4 SCAR=30.0
597 0 my $sum = 0;
598 0 my ( $n, $data );
599 0 ▶ if ( $data = shift )
Branch: 1 branch
BranchTrueFalseTotal
if ($data = shift()) { } 0 0 0
600 {
601 0 ▶ die 'Must call with an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
602 unless ref($data) eq 'ARRAY';
603 0 $n = @$data;
604 }
605 else
606 {
607 0 $data = $self->{data};
608 0 $n = $self->{n};
609 }
610 0 $sum += $_ * $_ for @$data;
611 0 return sqrt( $sum / $n );
612 }
613  
614 sub stdev
615 {
616 0 ▶ my $self = shift;
Subroutine stdev: not called CC=6 SCAR=37.4
617 0 my ( $n, $data, $mean );
618 0 ▶ if ( $data = shift )
Branch: 1 branch
BranchTrueFalseTotal
if ($data = shift()) { } 0 0 0
619 {
620 0 ▶ die 'Must call with an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
621 unless ref($data) eq 'ARRAY';
622 0 $n = @$data;
623 0 $mean = $self->mean($data);
624 }
625 else
626 {
627 0 $data = $self->{data};
628 0 $n = $self->{n};
629 0 ▶ $mean = $self->{mean} || $self->mean;
Condition0%0/3
$self->{'mean'} || $self->mean
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'mean'} || $self->mean
$self->{'mean'} $self->mean
Truth table0%0/3
A || B
A= $self->{'mean'}B= $self->mean
ABresult
1X1
011
000
630 }
631 0 ▶ die 'Cannot find the standard deviation with n = 1'
Branch: 1 branch
BranchTrueFalseTotal
if $n == 1 0 0 0
632 if $n == 1;
633 0 my $sum = 0;
634 0 $sum += ( $_ - $mean ) * ( $_ - $mean ) for @$data;
635 0 return sqrt( $sum / ( $n - 1 ) );
636 }
637  
638 sub range
639 {
640 0 ▶ my $self = shift;
Subroutine range: not called CC=6 SCAR=37.4
641 0 my ( $n, $data );
642 0 ▶ if ( $data = shift )
Branch: 1 branch
BranchTrueFalseTotal
if ($data = shift()) { } 0 0 0
643 {
644 0 ▶ die 'Must call with an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
645 unless ref($data) eq 'ARRAY';
646 0 $n = @$data;
647 }
648 else
649 {
650 0 $data = $self->{data};
651 0 $n = $self->{n};
652 }
653 0 my $min = $data->[0];
654 0 my $max = $data->[0];
655 0 for (@$data)
656 {
657 0 ▶ $min = $_ if $_ < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < $min 0 0 0
658 0 ▶ $max = $_ if $_ > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $max 0 0 0
659 }
660 0 return ( $min, $max );
661 }
662  
663 sub median
664 {
665 0 ▶ my $self = shift;
Subroutine median: not called CC=4 SCAR=30.0
666 0 my ( $n, $data );
667 0 ▶ if ( $data = shift )
Branch: 1 branch
BranchTrueFalseTotal
if ($data = shift()) { } 0 0 0
668 {
669 0 ▶ die 'Must call with an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 0 0 0
670 unless ref($data) eq 'ARRAY';
671 0 $n = @$data;
672 }
673 else
674 {
675 0 $data = $self->{data};
676 0 $n = $self->{n};
677 }
678 0 my @sorted = sort { $a <=> $b } @$data;
679 return (
680 0 ▶ ( $n & 0x1 )
Branch: 1 branch
BranchTrueFalseTotal
$n & 1 ? : 0 0 0
681 ? $sorted[ ( $n - 1 ) / 2 ]
682 : ( $sorted[ $n / 2 ] + $sorted[ $n / 2 - 1 ] ) / 2
683 );
684 }
685  
686 # Autoload methods go after =cut, and are processed by the autosplit program.
687  
688 1;
689  
690 __END__
↑ Summary Build »