Square Wave Generator

Generate an array of values that represent a square wave.
846 Downloads
Updated 5 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);
OR
[y] = squareWave(10,1,1);
OR
[y] = squareWave(10,1,-1,1);
OR
[y] = squareWave(10,1,-1,1,1);
OR
[y] = squareWave(10,1,-1,1,1,1e5);

Cite As

John Pritchard (2026). Square Wave Generator (https://www.mathworks.com/matlabcentral/fileexchange/33622-square-wave-generator), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Fourier Analysis and Filtering in Help Center and MATLAB Answers
Version Published Release Notes
1.3.0.0

Updated examples in help section of M-file to be more intuitive.

1.2.0.0

Examples in file description appropriately updated.

1.0.0.0