Square wave with values 0 to 1 rather than -1 to 1
11 views (last 30 days)
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)
Anamitra Datta
on 10 Apr 2021
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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!