# FT's in Mathematica

1. Aug 14, 2006

### natski

I've tried a simple plot of the FT of a simple cosine function with respect to omega and got some unimpressive results. The command I tried was:

Plot[FourierTransform[Cos[3000 t], t, ω], {ω, 2000, 4000}]

So I was expecting a nice delta function at 3000 but it's not visible or not present on the plot. How I can resolve this problem to see a spike?

2. Aug 18, 2006

### LENIN

I tride this myself yesterday and there is really a quite a large collection of problems here (but they are solvable).

1. First of all I just ride to evolute the function:
Code (Text):
FourierTransform[Cos[3000 t], t, ω]
I't took a long time so I advice you don't use 3000 but something smaller perhaps 30. Well anyway this is what I got out (when I used A instead of 3000):
Code (Text):
Sqrt[pi/2]*DiracDelta[-A+omega]+Sqrt[pi/2]*DiracDelta[A+omega]
2. Now the first of the real problems becomes visable. The DiracDelta function returns 0 for enything that isn't 0 and "DiracDelta[0]" if it is 0.
That means that it doesn't have a numerical value at A and it therefore can't be ploted at htat point. Now as far as the Fourier transformation goes this all fine but you wanted to see a line there, so lets try to make one. The idea is to replace the DiracDelta with something that can be drawn, I found that DiscreteDelta works just fine for these case. So now the code should look something like this:
Code (Text):
ft=FourierTransform[Cos[3000 t], t, ω]/.DiracDelta->DiscreteDelta
And should evolute to:
Code (Text):
Sqrt[pi/2]*DiscreteDelta[-A+omega]+Sqrt[pi/2]*DiscreteDelta[A+omega]
3. Now you have a function that returns 0 for everything except for A and -A where it returns Sqrt[pi/2]. But if you try to use Plot on it you will still get a streight line at 0. The problem now is in the Plot function works. What the Plot function really does is callculate your function at a number points (I belive theres a default of 25) and connects them with a curve. Well the thing is that these points aren't usually nice (for instance if you evoluted this function
Code (Text):
Plot[Sqrt[-1]*x,{x,1,3},PlotPoints->3]CODE] you would see in the errors that tzhe points it wanted to calculate where: a bit more then 1, something near but not exactly 2 and a bit less then 3). The probleme with ploting your function is that it misses the only point where it's not zero.There is however a way around this.

First make a list of values of your function:
[CODE]values=Table[{omega,ft},{omega,min,max,0.1}]
Witch should evoulte to something like:
Code (Text):
{{min,0},{min+0.1,0},{min+0.2,0},...}
Now you use the ListPlot function:
Code (Text):
ListPlot[values,PlotJoined->True]
This should give you a nice preaty plot. But if you use some strange values for A it might still miss it (I will see if there is enything that can be done about that and some othere smaller problems such as the hight of the peaks(now only Sqrt[pi/2])).

3. Mar 19, 2009

### kwchun

The LENIN's method misses some points as mentioned, because some numbers in omega table are odd. For example,
Code (Text):
0.1+0.2=0.30000000000000004`
This problem can be resolved using Rationalize. The following function works as intended.
Code (Text):
ft[ω_]:=DiscreteDelta[0.3-Rationalize[ω]]