How to make a square wave of bits from a ones and zeros vector?
9 views (last 30 days)
Show older comments
Carlos Alfredo Vega Aguilar
on 14 Feb 2021
Commented: Carlos Alfredo Vega Aguilar
on 23 Feb 2021
Hello everyone!
I'll really appreciate your help with this little problem.
I have a vector, to say something X, which has only 1's and 0's (bits), and I want to get a plot from this vector with a square shape. I would like to give to this plot the period of each bit to make a square wave... because if I plot only the vector X, I'll get peaks and not squares or pulses.
Thanks for your support!
I'll be reading your comments.
0 Comments
Accepted Answer
Walter Roberson
on 14 Feb 2021
x = randi([0 1], 1, 10)
stairs(x); ylim([-0.1 1.1])
Not like that? You need the bits to be separated ?
duty = 0.8;
xx = reshape([x; zeros(size(x))],1,[]);
t = [0:length(x)-1];
tt = reshape([t;t+duty], 1, []);
stairs(tt, xx); ylim([-.1 1.1])
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!
