3
$\begingroup$

Is there a built in function for a non-ideal square wave with finite rise and fall times to approximate digital signals?

I know this should be possible with a piece-wise function but I though Mathematica is so extensive there may be a built in function.

$\endgroup$
4
  • 2
    $\begingroup$ Can you give an example of that sort of square wave? $\endgroup$ Commented Jul 31, 2016 at 14:41
  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Jul 31, 2016 at 15:11
  • $\begingroup$ @axk: depends on what you want to do with the waveform. For signal processing I would use a pure square wave feeding a 1st order filter. Everything is kept linear, so you can do either numerical simulation or Laplace calculations. $\endgroup$ Commented Jul 31, 2016 at 18:02
  • $\begingroup$ I was thinking having a function that I can use in a differential equasion with DSolve to solve for voltages and currents in a simple buck converter type switching power supply. $\endgroup$
    – axk
    Commented Aug 1, 2016 at 13:11

2 Answers 2

11
$\begingroup$

In absence of a specific example perhaps a clipped triangle wave would be of use?

Manipulate[
  Plot[Clip[c*TriangleWave[x]], {x, 0, 3}],
  {c, 1, 30}
]

enter image description here

Two more options using filtering, though not directly as a function.

FIR:

sq = Table[SquareWave[x], {x, 0, 4, 0.01}];

Manipulate[ListLinePlot @ LowpassFilter[sq, ω], {ω, 0.05, 0.5}]

enter image description here

IIR:

Manipulate[
  ListLinePlot @ RecurrenceFilter[{{1, β}, {1}}, sq],
  {β, -0.90, -0.1}
]

enter image description here

$\endgroup$
3
$\begingroup$

SquareWave is a built-in function:

Plot[(1 + SquareWave[x]) /2, {x, 0, 3}, ExclusionsStyle -> Dotted]

enter image description here

For finite rise and fall times, you could try FourierSinSeries (change the parameters if you need):

mysquarewave[x_] := Evaluate[FourierSinSeries[SquareWave[x], x, 10,
  FourierParameters -> {1, 2 Pi}]];
Plot[(1 + mysquarewave[x]) /2, {x, 0, 3}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Yes, but if we consider OP's "finite rise and fall times", that's apparently not what s/he wants. (But OP should really clarify...) $\endgroup$ Commented Jul 31, 2016 at 17:06
  • $\begingroup$ @J.M. I submitted my answer too early... Fixed it! $\endgroup$ Commented Jul 31, 2016 at 17:45
  • 1
    $\begingroup$ I dunno... Gibbs might or might not be a problem for the second one. $\endgroup$ Commented Jul 31, 2016 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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