# Re and Im of fourier transform for shifted rectangular pulse

I'm currently trying to vizualize the relation between time and frequency domain and their behavior for a single rectangular pulse regarding different paramters. A special focus is set on the real Re and imaginary Im part of the frequency spectrum of a shifted pulse.

I wrote a Mathematica script that plots the pulse in time domain, the pulse's fourier transform in shape of the real and the imaginary part, and the absolute value of the real part as well. Further it manipulates the parameters duty cycle d, amplitude a, DC bias b, and time shift s.

Actually, the vizualization of the pulse in time domain works fine and as long as I do not implement the time shift for the Fourier transform the spectra are calculated correctly! However, the Fourier is burning my time and nerves since I tried to implement that functionality. I am pretty new in the fields of Mathematica, so there might be fundamental mistakes in thinking or coding which you will hopefully tell me ... ;o)

Here is my current script which is working so far, but the time shift is not implemented for Fourier:

Manipulate[
Grid[{
{
Plot[a * UnitBox[(t - s)/d] + b, {t, -2.1, 2.1}, PlotLabel -> "Pulse",
Exclusions -> None, Filling -> Axis, PlotRange -> 1.0,
PerformanceGoal -> "Speed", ImageSize -> Medium],
Plot[Abs[FourierTransform[a * UnitBox[t/d] + b, t, f,
FourierParameters -> {1, -1}]], {f, -25, 25}, PlotLabel ->
"Absolute Real Part", Exclusions -> None, Filling -> Axis, PlotRange
-> 1.0, PerformanceGoal -> "Speed", ImageSize -> Medium]
},
{
Plot[Re[FourierTransform[a * UnitBox[t/d] + b, t, f, FourierParameters
-> {1, -1}]], {f, -25, 25}, PlotLabel -> "Real Part", Exclusions ->
None, Filling -> Axis, PlotRange -> 1.0, PerformanceGoal -> "Speed",
ImageSize -> Medium],
Plot[Im[FourierTransform[a * UnitBox[t/d] + b, t, f, FourierParameters
-> {1, -1}]], {f, -25, 25}, PlotLabel -> "Imaginary Part",
Exclusions -> None, Filling -> Axis, PlotRange -> 1.0,
PerformanceGoal -> "Speed", ImageSize -> Medium]
}
}],
Style["Pulse-Width Signal", 12, Bold], {{d, 0.5, "Duty Cycle"}, 0.001,
1.0, 0.001}, {{s, 0, "Time Shift"}, -2.0, 2.0, 0.1}, {{a, 1.0,
"Amplitude"}, -2.0, 2.0, 0.1}, {{b, 0.0, "DC Bias"}, -1.0, 1.0, 0.1},
ControlPlacement -> Left
]


Currently, the time-to-frequency transformation works for a rectangular pulse of certain period, duty cycle, amplitude, and DC bias. Only the time shift s impedes the vizualization of the relations between pulse in time and spectrum in frequency. Including the calculation with time shift s leads to abortion or endless processing.

To increase clearity and efficiency I tried to centralize the calculations of the rectangular pulse function and its Fourier transform, but the definitions usually did not work and I do not know why!

Rectangular pulse function with time shift:

a * UnitBox[(t - s)/d] + b


Tried definition:

myPWM[t_, duty_, ampl_, bias_, shift_] :=
ampl * (UnitBox[(t - shift)/duty]) + bias;

myPWMF[t_, duty_, ampl_, bias_, shift_] :=
FourierTransform[myPWM[t, duty, ampl, bias, shift], t, f];


Is it the wrong way to define such functions? Including myPWM and myPWMF leads to abortion, endless processing and empty diagrams.

I hope you can help me to finish this nice vizualization! Thank you very much in advance!

• Your code with the time shift (I mean with (t-s)/d instead of t/d) works but It takes 40 secondes to update the image (my machine : I7). This is not normal. Mar 2, 2017 at 19:41
• The speed is a way better if you enclose the first argument of each Plot[...] in a Evaluate[...]. Mar 2, 2017 at 19:52

Take a look at the form of your Fourier transform of the rectangular pulse.

FourierTransform[a UnitBox[(t-s)/d]+b,t,w,FourierParameters->{1,-1}]


Note that your pulse width is always going to be positive, so simplify

% //Simplify[#,d>0]&


Now trick Mathematica into using the Sinc form for the amplitude envelope

% /. Sin[d w/2]->(d w/2) Sinc[d w/2]


Finally convert the complex phase term to an exponential form

% // TrigToExp


You should get a result that looks like

2 b \[Pi] DiracDelta[w] + a d Exp[-I s w] Sinc[d w/2]


This is what you should be plotting for your pulse spectrum. For this I recommend plotting the real and imaginary parts together so you can see how they play off each other.

Module[{f},
f[w_] := 2 b \[Pi] DiracDelta[w] + a d Exp[-I s w] Sinc[d w/2];
Plot[{Re[f[w]],Im[f[w]]},{w,-20,20},PlotRange->All];
]


What you will observe, if you put this form of the plot within your Manipulate function is that the time shift of your pulse corresponds to a frequency modulation of the spectrum.

• Thank you for your detailed answer! Nevertheless, I was not able to reconstruct what you tried to explain to me. Probably I'm not experienced enough in Mathematica ;)
– FloW
Mar 6, 2017 at 14:45
• In Module, you may want to add {f, a = 1, b = 1, d = 1, s = 1} to make the plot work.
– Jens
Apr 2, 2017 at 2:40

Your code gives numeric values to d,s,a,d,b,f and then only after calculate the FourierTransform. It is better to first calculate the FourierTransform litterally, then give numeric values to d,s,a,d,b when the cursor is moved (to obtain a formula with only f as litteral value) and finally to vary f to trace the curve.

myOpts={Exclusions -> None, Filling -> Axis, PlotRange -> 1.0,
PerformanceGoal -> "Speed", ImageSize -> Medium};

myOpts01={
PlotRange-> {{-25,25},{-1,1},{-1,1}},PlotPoints->{100,2},
PlotLabel ->"Real and Imaginary Parts",BoxRatios->1,Exclusions->None,PerformanceGoal->"Speed",
ImageSize->Medium,PlotStyle->Directive[Opacity[0.5],Specularity[White,30],Orange],Boxed-> False,
Axes-> True,AxesStyle-> Thick,AxesOrigin->{0,0,0},
Mesh->Full,ViewPoint->{1.4,2.9,0.786},ViewVertical->{-0.277,0.89,-0.34}};

ClearAll[exp00,exp01]

Block[{a,s,d,b,t,f} ,
exp00[a_,s_,d_,b_,t_]=a * UnitBox[(t - s)/d] + b;
exp01[a_,s_,d_,b_,f_]=FourierTransform[exp00[a,s,d,b,t], t, f,FourierParameters -> {1, -1}];
]

Manipulate[
Grid[{
{
Plot[exp00[a,s,d,b,t], {t, -2.1, 2.1}, PlotLabel -> "Pulse",Evaluate[myOpts]],
Plot[Abs[exp01[a,s,d,b,f]], {f, -25, 25}, PlotLabel ->"Absolute Real Part", Evaluate[myOpts]]
},
{
Plot[Re[exp01[a,s,d,b,f]], {f, -25, 25}, PlotLabel -> "Real Part", Evaluate[myOpts]],
Plot[Im[exp01[a,s,d,b,f]], {f, -25, 25}, PlotLabel -> "Imaginary Part",Evaluate[myOpts]]
},
{ParametricPlot3D[{f,k Re[exp01[a,s,d,b,f]],k Im[exp01[a,s,d,b,f]]}, {f, -25, 25},{k,0,1},Evaluate[myOpts01]]}
}],
Style["Pulse-Width Signal", 12, Bold], {{d, 0.5, "Duty Cycle"}, 0.001,
1.0, 0.001}, {{s, 0.2, "Time Shift"}, -2.0, 2.0, 0.1}, {{a, 1.0,
"Amplitude"}, -2.0, 2.0, 0.1}, {{b, 0.0, "DC Bias"}, -1.0, 1.0, 0.1},
ControlPlacement -> Left
]


Notes :
* The DC Bias corresponds in the frequency domain to a Dirac. Plot[...] does not render this Dirac.
* I'm not sure that Block[...] is a good practise. It is usefull only if d,s,a,d,b are already defined when the lines exp00=... and exp01=... are evaluated. Formal symbols may be a better solution. Or maybe the opion Ìnitialization of Manipulate ...

• Thank you very much for that solution, it works fine!
– FloW
Mar 6, 2017 at 14:48