1
$\begingroup$

I'm currently working on an engineering exercise that goes as such: enter image description here

I know that I need a step function to model the square waves, but I'm having trouble finding the right functions to generate the list. What's the best approach. (Note: it is assumed in the Fourier function that a=1 and b=-1)

$\endgroup$
1
$\begingroup$

One way to plot it is

ClearAll[t, f, g];

td   = 1;
T0   = 4;
m    = 8;
delT = T0/50;

f[t_] := Piecewise[{{1, t < td}, {0, True}}];
g[t_] := f[Mod[t, T0]]

Plot[g[t], {t, 0, m T0}, Exclusions -> None, PlotStyle -> Red, 
    GridLines -> Automatic, GridLinesStyle -> LightGray]

Mathematica graphics

Now you can sample it and do Fourier on it

data = Table[g[n*delT], {n, 0, Round[m T0/delT - 1]}];
ListLinePlot[data]

Mathematica graphics

Fourier[data]

Check help under Fourier applications section for additional commands on using Fourier and plotting the spectrum.

$\endgroup$
  • $\begingroup$ Well I applied according to the example and tried to work out the solutions in the book. I'm wondering if I got this right: ` ClearAll["Global*"] td = 1; T0 = 4; m = 8; delT = T0/50; f[t_] := Piecewise[{{1, t < td}, {0, True}}]; g[t_] := If[t > T0, g[t - T0], f[t]] data = Table[g[n*delT], {n, 0, Round[m T0/delT]}]; ft = Fourier[data, FourierParameters -> {1, -1}]; datf = Table[{(k - 1)/(delT), 2. Abs[ft[[k]]]}, {k, 1, 100}]; ListPlot[datf[[1 ;; 100]], Filling -> Axis, AxesLabel -> {"f(Hz)", "|\!\(\*SubscriptBox[\(G\), \(n\)]\)|"}] $\endgroup$ – TexMexDex Dec 14 '19 at 7:46

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