Square wave with values 0 to 1 rather than -1 to 1
Show older comments
Hi,
I know that the square(t) function produces a wave with an amplitude from -1 to 1, is it possible to produce it from 0 to 1 instead?
Thanks
1 Comment
Md Maidul Islam
on 27 Feb 2019
Edited: Md Maidul Islam
on 30 Apr 2019
t=0:0.1:10;
x=0.5*(square(t)+1);
plot(t,x)
Answers (2)
madhan ravi
on 5 Dec 2018
t = linspace(0,1).';
x = square(t);
1 Comment
Michael Au-Duong
on 5 Dec 2018
Anamitra Datta
on 10 Apr 2021
0 votes
The above answers are wrong. It should be:
Assuming your period is 2*pi
x = 0.5*square(t)+0.5
This produces a square wave of 1 to 0 though in a cycle
If you need 0 to 1 in a cycle, you should do:
x = 0.5*square(t-pi)+0.5
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!