updating tophat fft

This commit is contained in:
caes 2016-08-12 05:14:03 -04:00
parent 91467064d3
commit 71bd494206
2 changed files with 40 additions and 27 deletions

View File

@ -30,7 +30,6 @@ case $1 in
done done
echo "$gnuplot_input"|perl -pe 's|␤|\n|g' > ${gnuplot_file} echo "$gnuplot_input"|perl -pe 's|␤|\n|g' > ${gnuplot_file}
gnuplot $gnuplot_file gnuplot $gnuplot_file
;; ;;
"lags"|"lag"|"delay"|"delays") "lags"|"lag"|"delay"|"delays")
@ -52,10 +51,10 @@ case $1 in
;; ;;
"tophat") "tophat")
gnuplot_file=tophat_w_fft.gp gnuplot_file="tophat_w_fft.gp"
;; ;;
*) *)
echo "Did not understand plot type." echo "Did not understand plot type."
;; ;;
esac esac

View File

@ -1,7 +1,7 @@
#!/usr/bin/env perl #!/usr/bin/env perl
use feature say; use feature say;
use utf8; use utf8;
use PDL; use PDL;
use PDL::FFT; use PDL::FFT;
use PDL::IO::Misc; use PDL::IO::Misc;
@ -9,38 +9,52 @@ use PDL::IO::Misc;
my $twoPI = 2*3.1415926539; my $twoPI = 2*3.1415926539;
# space parameters # space parameters
our $Δt=.001; our $xres=.001;
our $xmin = 0; our $xmin = 0;
our $xmax = 250; our $xmax = 250;
our $num_bins = ($xmax-$xmin)/$Δt; our $num_bins = ($xmax-$xmin)/$xres;
# tophat parameters
my $μ1=15;
my $Δ1=5; # full width
my $μ2=15;
my $Δ2=5; # full width
my $μ3=15;
my $Δ3=5; # full width
say "Creating $num_bins bins"; say "Creating $num_bins bins";
# Complex Number z(x) = u(x) + iv(x) # Complex Number z(x) = u(x) + iv(x)
my @th_list=tophat(10,7); my @th_list=tophat($μ1,$Δ1);
my $u = pdl(@th_list); my $u = pdl(@th_list);
my $v = zeroes($u); my $v = zeroes($u);
# Output time-domain tophat
open $tophattab, '>', 'analyses/tables/tophat.tab'; foreach (('1','2','3')) {
for ($i=0; $i < $num_bins; $i++) {
my $x_coord = ($xmax-$xmin)*($i/$num_bins) + $xmin; # Output time-domain tophat
say $tophattab "$x_coord $th_list[$i]"; open $tophattab, '>', "analyses/tables/tophat${$_}.tab";
for ($i=0; $i < $num_bins; $i++) {
my $x_coord = ($xmax-$xmin)*($i/$num_bins) + $xmin;
say $tophattab "$x_coord $th_list[$i]";
}
close $tophattab;
# Transform z(x) to Z(1/x) = U(1/x) + iV(1/x)
my $U = $u;
my $V = $v;
fft($U,$V);
# Determine frequency coordinates
my $num_elements = nelem($U);
say "Found $num_elements elements.";
$f = $U->xlinvals(-($num_elements/2-1)/$num_elements/$xres,1/2/$xres)->rotate(-($num_elements/2 -1));
my $φdiff = atan2($V,$U);
my $timelag = $φdiff/($twoPI*$f);
wcols $f,$timelag,"analyses/tables/tophat_fft${$_}.tab";
} }
close $tophattab;
# Transform z(x) to z(1/x) = u(1/x) + iv(1/x)
fft($u,$v);
# Determine frequency coordinates
my $num_elements = nelem($u);
say "Found $num_elements elements.";
$f = $u->xlinvals(-($num_elements/2-1)/$num_elements/$Δt,1/2/$Δt)->rotate(-($num_elements/2 -1));
my $φdiff = atan2($v,$u);
my $timelag = $φdiff/($twoPI*$f);
wcols $f,$timelag,'analyses/tables/tophat_fft.tab';
sub tophat { sub tophat {
(my $mean,my $width) = @_; (my $mean,my $width) = @_;