Mathematica Solving a Problem with Fourier Transform in Mathematica

  • Thread starter Thread starter natski
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
The discussion centers on plotting the Fourier Transform of a cosine function, specifically Cos[3000 t], and the challenges faced in visualizing the expected delta function at 3000. Initial attempts using the FourierTransform command yielded unsatisfactory results, as the DiracDelta function does not provide numerical values for plotting. To address this, participants suggested replacing DiracDelta with DiscreteDelta, allowing for a function that returns non-zero values at specific points. However, the Plot function still struggled to visualize these points due to its method of sampling. A workaround involved creating a list of values for the function and using ListPlot to generate a clearer representation. Additionally, issues with floating-point precision were noted, with a recommendation to use Rationalize to ensure accurate calculations. Overall, the discussion highlights the complexities of plotting Fourier Transforms and offers practical solutions for better visualization.
natski
Messages
262
Reaction score
2
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?
 
Physics news on Phys.org
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:
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:
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 let's 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:
ft=FourierTransform[Cos[3000 t], t, ω]/.DiracDelta->DiscreteDelta

And should evolute to:
Code:
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 believe there's 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:
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:
{{min,0},{min+0.1,0},{min+0.2,0},...}

Now you use the ListPlot function:
Code:
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])).
 
LENIN said:
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])).

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

Similar threads

Replies
4
Views
3K
Replies
1
Views
3K
Replies
2
Views
483
Replies
2
Views
9K
Replies
2
Views
4K
Back
Top