# How can I visualize a frequency as square wave?

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

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


and has the following result. What do I have to modify in my code in order to get that square wave form, shown above ?

• Search SquareWave[ ] in the docs – Dr. belisarius Nov 25 '15 at 20:36
• 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)$. – IPoiler Nov 25 '15 at 21:04
• The rapid fluctuation near the origin is something of a clue that inverting the plot variable is probably not what you want to do. – Daniel Lichtblau Nov 25 '15 at 21:12

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]

• What is the reason for the 2Pi in the equation and the 10^(-7) and .01 in the t definition ? – Jorgos Nov 25 '15 at 21:33
• Why does Mathematica plots a strange diagram by editing the t range from .01 to 1 e.g. {t,0,1} ? – Jorgos Nov 25 '15 at 21:42
• @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. – David G. Stork Nov 25 '15 at 21:48