1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# Play safe
free @all
# Show how padding affects results on fft
# Tell gnuplot our specifications
pmode clear; set data style line; set nolog
# Define a few macros for the sake of it
macro dofft 2
# Append _FT to the name of transformed vectors.
fft $1 $2 $1_FT $2_FT
let POW$1 = ($1_FT^2 + $2_FT^2)
stop
macro doinvfft 2
# Append _IFT to the name of inverse tranformed vectors.
invfft $1 $2 $1_IFT $2_IFT
let POW$1 = ($1_IFT^2 + $2_IFT^2)
stop
# Take the next power of 2 larger than 700.
set data 1024
# Generate an identity permutation
let n=0 ; N=n++
let IM=0
let x=0 ; X = (x++ * 2 * pi/data)
# A will be created with 1024 so it will be
# filled with zeros from 700 to 1024.
let A=0
set data 700
let A=cos(100*X) + sin(100*X) + cos(10*X) + sin(10*X)
# Go back to 1024 to do the fft.
set data 1024
echo Plotting function...
echo Note that it is zero padded from 700 to 1024.
gnu N A
pause -1 "Hit return"
# Do the Fourier transform using our user-defined macro.
dofft A IM
# Only plot the first half of it.
# Change the `data' constant into a variable.
unlock data
# Let the size of vectors be half for a while since real vectors
# transform in symmetrical frequency functions (f(x) = f(-x)).
let data/=2
echo Plotting the Fourier transform...
gnu N POWA
echo Look how data is affected (shoulders around 10 and 100)
pause -1 "Hit return"
# Go back to original size.
let data*=2
# Change the `data' variable back to a constant.
lock data
# Do the inverse Fourier transform using our user-defined macro.
doinvfft A_FT IM_FT
echo Plotting real function transformed back...
gnu N A_FT_IFT
|