Hello everyone. I have the following periodic function:
x(t)=summation [x0(t-nT)] from n=-infinity to n=+infinity
where x0(t)=(1+cos(2 pi f0 t)) rect(t/T)
How can I get the coefficients for k=0,1,2 of the Fourier series?
Thank you for your time.
Hello everyone. I have the following periodic function:
x(t)=summation [x0(t-nT)] from n=-infinity to n=+infinity
where x0(t)=(1+cos(2 pi f0 t)) rect(t/T)
How can I get the coefficients for k=0,1,2 of the Fourier series?
Thank you for your time.
What’s your WL code for rect[t/T]?
Hello @Michael Rogers. This is the code: rect(t/T)=HeavisideTheta[t + (T/2)] - HeavisideTheta[t - (T/2)].
I still feel like I’m assuming something, but perhaps this is what you’re after?:
rect[t_, T_] := HeavisideTheta[t + (T/2)] - HeavisideTheta[t - (T/2)]
x0[t_] := (1 + Cos@(2 Pi f0 t)) rect[t, T]
sum = Sum[x0@(t - n T), {n, -Infinity, Infinity}, Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 0, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 1, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 2, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]
Thank you so much Michael! I have another question: if I want to impose f0=1/(2T), how can I modify the code? I tried in the following way, but Mathematica shows errors:
rect[t_, T_] := HeavisideTheta[t + (T/2)] - HeavisideTheta[t - (T/2)]
x0[t_] := (1 + Cos@(2 Pi f0 t)) rect[t, T]
f0 := 1/(2T)
sum = Sum[x0@(t - n T), {n, -Infinity, Infinity}, Assumptions -> T > 0]
FourierCoefficient[sum, t, 0, FourierParameters -> {1, 2 Pi/T},
Assumptions -> T > 0]
FourierCoefficient[sum, t, 1, FourierParameters -> {1, 2 Pi/T},
Assumptions -> T > 0]
FourierCoefficient[sum, t, 2, FourierParameters -> {1, 2 Pi/T},
Assumptions -> T > 0]
Hi,
Sorry for the delay.
One way is to take the old coefficient and plug in the value for f0 like this:
oldFourierCoefficient /. f0 -> 1/(2 T)
It seems faster than recomputing the integrals. Also, I found the coefficient 1 gave an odd and incorrect result, which sometimes happens with integration.
I don’t get any errors, so maybe you’re using a different version (or perhaps you have defined some variable earlier that is causing some problem). I’m using V11.1.1.
Hi,
Sorry for the delay.
One way is to take the old coefficient and plug in the value for f0 like this:
oldFourierCoefficient /. f0 -> 1/(2 T)
It seems faster than recomputing the integrals. Also, I found the coefficient 1 gave an odd and incorrect result, which sometimes happens with integration.
I don’t get any errors, so maybe you’re using a different version (or perhaps you have defined some variable earlier that is causing some problem). I’m using V11.1.1.
Hi @Michael Rogers. I tried to use your statement after and also before the code.
rect[t_, T_] := HeavisideTheta[t + (T/2)] - HeavisideTheta[t - (T/2)]
x0[t_] := (1 + Cos@(2 Pi f0 t)) rect[t, T]
sum = Sum[x0@(t - n T), {n, -Infinity, Infinity},
Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 0, FourierParameters -> {1, 2 Pi/T},
Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 1, FourierParameters -> {1, 2 Pi/T},
Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 2, FourierParameters -> {1, 2 Pi/T},
Assumptions -> f0 > 0 && T > 0]
oldFourierCoefficient /. f0 -> 1/(2 T)
In this case the output does not change. Actually Mathematica shows two outputs, the first is the same as before and the second is “oldFourierCoefficient”.
Returning to the error that you noted about coefficient 1, after the (manual) substitution of f0=1/2T, the result is 2/(3 Pi). This is right, is the result of my professor.
You should use one of the three old Fourier Coefficients in place of oldFourierCoefficient. In the code just posted, they would be represented by %, %%, %%%. You could also store them in a list:
generalcoeffs = {
FourierCoefficient[sum, t, 0, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 1, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]
FourierCoefficient[sum, t, 2, FourierParameters -> {1, 2 Pi/T}, Assumptions -> f0 > 0 && T > 0]};
generalcoeffs /. f0 -> 1/(2 T)