0
$\begingroup$

I'm trying to get a typical square wave of a 16MHz and 50Hz signal withing a y-range of 0 to 1.

enter image description here

My code is:

hz[period_] := 1/period
Plot[SquareWave[{0, 1}, hz[x]], {x, 0, 3}, Exclusions -> None]

and has the following result.

enter image description here

What do I have to modify in my code in order to get that square wave form, shown above ?

$\endgroup$
  • $\begingroup$ Search SquareWave[ ] in the docs $\endgroup$ – Dr. belisarius Nov 25 '15 at 20:36
  • 1
    $\begingroup$ Take care with how you've defined the independent variable in the SquareWave function. What you essentially have is $S(\frac{1}{x})$ (where $S$ is a square wave function) but you most likely want something like $S(50x)$ and $S(16\times 10^6 x)$. $\endgroup$ – IPoiler Nov 25 '15 at 21:04
  • 1
    $\begingroup$ The rapid fluctuation near the origin is something of a clue that inverting the plot variable is probably not what you want to do. $\endgroup$ – Daniel Lichtblau Nov 25 '15 at 21:12
3
$\begingroup$
Plot[.5 (1 + SquareWave[2 π (16 10^6) t]), 
{t, 0, 10^(-7)},
ExclusionsStyle -> Dotted]

and

Plot[.5 (1 + SquareWave[2 π 50 t]), 
{t, 0, .01},
ExclusionsStyle -> Dotted]
$\endgroup$
  • $\begingroup$ What is the reason for the 2Pi in the equation and the 10^(-7) and .01 in the t definition ? $\endgroup$ – Jorgos Nov 25 '15 at 21:33
  • $\begingroup$ Why does Mathematica plots a strange diagram by editing the t range from .01 to 1 e.g. {t,0,1} ? $\endgroup$ – Jorgos Nov 25 '15 at 21:42
  • $\begingroup$ @Jorgos: Sin[ ] goes through one cycle when its argument goes through $2 \pi$. The $10^{-7}$ is a range where the structure of your function is visible. If you change the range in the second figure to {t, 0, 1}, you get so many cycles of the square that they cannot be rendered well. $\endgroup$ – David G. Stork Nov 25 '15 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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