Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Fast fourier transform' topicStudent Support Forum > General > "Fast fourier transform"

Next Comment >Help | Reply To Topic
Author Comment/Response
Sean
07/16/13 7:13pm

Below I have a code of vibrating string. How can I tell Mathematica to do a Fast Fourier Transform to plot the power and frequency?

c = 300; (* In meters per second *)
epsilon = .000002; (* Spring stiffness *)
L = 1; (* In meters *)
Deltax = .005; (* In meters *)
Deltat = Deltax/(4*c); (* In seconds *)
M = L/Deltax;
r = c*Deltat/Deltax;

xlast = 1;
xini = 0;
iini = 0; ilast = IntegerPart[(xlast - xini)/Deltax];
tlast = .0375;
tini = 0;

nini = 0; nlast = IntegerPart[(tlast - tini)/Deltat];
x[iini] = xini;
x[xlast] = xlast;

k = 1000.0;(* In meters squared *)
x0 = 0.3 ;

For[i = iini, i <= ilast, i++, y[i, 0] = 0.0; y[i, -1] = 0;];
(* End for i *)

For[i = iini, i <= ilast, i++,
x[i] = x[iini] + i*Deltax;
y[i, 0] = Exp[-k (x[i] - x0)^2];
y[i, -1] = Exp[-k (x[i] - x0)^2];

];(* end for i *)

amplitude = Max[Table[Abs[y[i, 0]], {i, iini, ilast}]];
txy[0] = Table[{x[idum], y[idum, 0]}, {idum, iini, ilast}];
ListPlot[txy[0], PlotRange -> {{xini, xlast}, {-amplitude, amplitude}}]




For[i = iini, i <= ilast, i++, y[i, 0] = 0.0; y[i, -1] = 0;];



For[n = nini, n <= nlast, n++,

For[i = iini + 1, i <= ilast - 1, i++,

y[i, n + 1] = (2 - 2*r^(2) - 6*epsilon*r^(2)*M^(2)) *y[i, n] -
y[i, n - 1] +
   r^(2)*(1 + 4*epsilon*M^(2))*(y[i + 1, n] + y[i - 1, n])
   - epsilon*r^(2)*M^(2)*(y[i + 2, n] + y[i - 2, n]);
];

(* Boundary conditions *)

y[-1, n + 1] = -y[1, n + 1]; y[M + 1, n + 1] = -y[M - 1, n + 1];

txy[n + 1] = Table[{x[idum], y[idum, n + 1]}, {idum, iini, ilast}];
];(* end for n *)
(** End of time stepping **)



Manipulate[
ListPlot[txy[n], PlotRange -> {{xini, xlast}, {-2*amplitude,
2 amplitude}}]
, {n, nini, nlast - 1, 1}
](* end Manipulate *)





URL: ,

Subject (listing for 'Fast fourier transform')
Author Date Posted
Fast fourier transform Sean 07/16/13 7:13pm
Re: Fast fourier transform Bill Simpson 07/20/13 1:06pm
Next Comment >Help | Reply To Topic