image thumbnail

Square Wave Generator

version (1.65 KB) by John Pritchard
Generate an array of values that represent a square wave.


Updated 05 Nov 2011

View License

This is a simple function that returns an array of values that represent a square wave based on two essential inputs (total time and period) and four optional inputs (plot option, minimum amplitude, maximum amplitude, and resolution).

[f] = squareWave(time,per,plotChk,Amin,Amax,res)

Units are arbitrary, but time and amplitude are assumed.

The following examples illustrate its use:

[y] = squareWave(10,1);
[y] = squareWave(10,1,1);
[y] = squareWave(10,1,-1,1);
[y] = squareWave(10,1,-1,1,1);
[y] = squareWave(10,1,-1,1,1,1e5);

Cite As

John Pritchard (2021). Square Wave Generator (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!