Use the formula you mentioned above, and define the dataset "ds1". It cannot be a perfect rectangular wave form, you have to define a short period of time for rising and falling, such as 0.01s, depending on your frequency of the wave form. The dataset is more like, (0,0) (0.99,0) (1,1) (1.99,1)...