And finally (cue human-interest story), the version using
PDL::FFTW3; unfortunately for me I had to learn about power spectra and then convert Math::FFT's
spctrm code into a small PDL function:
use strict;
use warnings;
use PDL;
use PDL::FFTW3;
use PDL::Graphics::Simple;
my $filePath = $ARGV[0] // "testData.txt";
my @data = do { open my $fh, $filePath or die "Can't open $filePath: $
+!"; local $/; split /\s+/, <$fh> };
sub spectrum {my ($d)=@_;
my $hn=$d->dim(0)-1;
my $a2=$d->abs2/(($hn*2)**2);
$a2->slice([1,$hn-1])*=2;
$a2;
}
my $spectrum = spectrum(rNfft1 pdl(\@data));
$spectrum = $spectrum->slice('1:-1'); # Remove DC signal component
line pdl($spectrum);
print "ret> "; <STDIN>;
If you're into IRC, then next time you feel you might benefit from using PDL but don't feel 100% clear on where to start, do feel free to join #pdl on irc.perl.org and ask questions! A lightweight way to do so is on the MetaCPAN page for various PDL modules, with the "Chat with us" link.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.