#9729: Moving the discrete fourier interact from wiki into the library.
--------------------------------+-------------------------------------------
Reporter: punchagan | Owner: itolkov, jason
Type: enhancement | Status: needs_review
Priority: minor | Milestone:
Component: interact | Keywords:
Author: Puneeth Chaganti | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
--------------------------------+-------------------------------------------
Comment(by pang):
Replying to [comment:3 pang]:
Sorry, forgot to copyandpaste some details
{{{
def plot_bars(ls, lenght = 1):
return (sum(polygon2d([(x-lenght/2,0),(x+lenght/2,0),
(x+lenght/2,y),(x-lenght/2,y)])
for x,y in ls) +
sum(line2d([(x-lenght/2,0),(x+lenght/2,0),
(x+lenght/2,y),(x-lenght/2,y),(x-lenght/2,0)],
rgbcolor=(0,0,0))
for x,y in ls))
import scipy.fftpack as Fourier
var('x')
@interact
def discrete_fourier(f = input_box(default=sum([sin(k*x) for k in
range(1,5,2)])),
treshold = slider(0,0.1,0.01,0.01)):
pbegin = -float(pi)
pend = float(pi)
html("<h3>Function plot and its discrete Fourier transform</h3>")
show(plot(f, pbegin, pend, plot_points = 512), figsize = [4,3])
f_vals = [f(x=ind) for ind in srange(pbegin, pend,(pend-
pbegin)/512.0)]
my_fft = Fourier.fft(f_vals)
L = len(my_fft)
ls = ([(j, abs(my_fft[j])) for j in
range(-floor(L/2)+1,floor(L/2)+1)])
M = max(v for j,v in ls)
max_index = max(j for j in range(L) if ls[j][1] > treshold*M)
min_index = min(j for j in range(L) if ls[j][1] > treshold*M)
show(plot_bars(ls[max(min_index-5,0):min(max_index+5,L)]), figsize =
[4,3])
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9729#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.