Solving a Problem with Fourier Transform in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter natski
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

The discussion focuses on resolving issues with plotting the Fourier Transform (FT) of a cosine function in Mathematica. The original command, Plot[FourierTransform[Cos[3000 t], t, ω], {ω, 2000, 4000}], fails to display the expected delta function at 3000 due to the nature of the DiracDelta function. The solution involves replacing DiracDelta with DiscreteDelta and utilizing ListPlot to visualize the results effectively. Additionally, the use of Rationalize addresses precision issues in the omega values.

PREREQUISITES
  • Familiarity with Fourier Transform concepts in signal processing.
  • Basic understanding of Mathematica syntax and functions.
  • Knowledge of DiracDelta and DiscreteDelta functions in Mathematica.
  • Experience with plotting functions in Mathematica, specifically using Plot and ListPlot.
NEXT STEPS
  • Explore the use of DiscreteDelta in Mathematica for visualizing impulse functions.
  • Learn about the Rationalize function in Mathematica to handle numerical precision issues.
  • Investigate advanced plotting techniques in Mathematica, including customizing PlotPoints.
  • Study the implications of Fourier Transform on different types of signals, particularly in signal processing.
USEFUL FOR

Mathematica users, signal processing engineers, and anyone interested in visualizing Fourier Transforms and handling numerical precision in computational plots.

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 height 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 height 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 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K