Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Started playing with Mathematica a week ago. Now I'm on some more "advanced" stuff and really can't figure out what is happening.

I'm trying to get the spectrum of this signal, $x(t) = 110 \sin{(120\pi t)} + 50 \cos{(360\pi t + \pi/3)}$. I have solved this by hand and got the coefficients, but I can't get them at all using Mathematica.

My code:

y[t_] = 110 Sin[120 Pi t] + 50 Cos[360 Pi t + Pi/3];
X[k_] = Integrate[y[t]*Exp[-2 Pi I t k/T], {t, -T/2, T/2}]

Integration is rather slow but that is expected of symbolic integration. What I'm wondering is the amplitude of the spectrum. It just disappears. Abs[X[2]] should be 55 but it's not. Same for every other defined value of the spectrum.

I used

DiscretePlot[Abs[Limit[X[k], k -> i]], {i, -10, 10}]

to get the plot but the amplitudes aren't correct. I used Table on with the limit and complex numbers were defined for correct $k$ but their values were wrong (missing amplitude).

Tried the same with MATLAB and I could see the exact values of amplitude appearing in the "prettified" version of the equation. In Mathematica, the spectrum function seems to be lacking these constants (I did substitute T for a value at one point).

Could this be a precision problem? How can I do it right?

share|improve this question
maybe FourierTransform will be useful. Be sure to look at the "Details and Options" bit in the docs to see how to fix the constants you want. –  acl Apr 13 '13 at 22:15
Nope, fourier transform would be used mostly for the non-periodic functions, this one is periodic, series is what I want. But!, I'm not really looking for the series, I'm just integrating by the definition but the spectrum values just aren't right. I am reading the documentation and have checked it for the functionality I want and couldn't find something similiar. –  Looft Apr 13 '13 at 22:21
Do you know the difference between = and :=? See this question for things you ought to know. –  m_goldberg Apr 13 '13 at 22:45
Well it seems to me that you can get a Fourier series using FourierSeries[110 Sin[120 Pi t] + 50 Cos[360 Pi t + Pi/3], t, 400, FourierParameters -> {1, -Pi}] (you can change the parameters as desired). –  acl Apr 13 '13 at 23:21
Your signal has a period of 1/60, meaning a frequency of 60. X[2] would correspond to the component with frequency 120 in the spectrum. However your signal has no component of that frequency. So X[2]=0. If that's what you mean by "it just disappears" then that's why. (acl's answer shows the correct spectrum upto a normalizing constant.) –  Aky Apr 14 '13 at 9:43
show 1 more comment

closed as too localized by Sjoerd C. de Vries, m_goldberg, Yves Klett, whuber, Oleksandr R. Apr 17 '13 at 18:09

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 4 down vote accepted

If for pedagogical purposes you do not wish to use FourierSeries, here's one approach:

ClearAll[x, y];
y[t_] = 110 Sin[120 Pi t] + 50 Cos[360 Pi t + Pi/3];
x[k_] := With[{T = 1/60},
  Integrate[y[t]*Exp[-2 Pi I t k/T], {t, 0, T}]

DiscretePlot[Abs[x[i]], {i, -10, 10}]

enter image description here

You're not specifying T anywhere in your example. I don't actually know what you are trying to do, so modify this as appropriate.

share|improve this answer
This is entirely my mistake, I apologize for the inconvenience. Your answer is correct and it definitely helped me discover my own mistake :D For some reason I have forgotten the 1/T in the integral. –  Looft Apr 14 '13 at 9:28
@Leolinus no problem –  acl Apr 14 '13 at 10:14
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.