How to generate a square wave with random normal distributed period and pulse width?

Hi,
for example: a square wave signal with a period of 40-50 and a pulse width of 20-30, amplitude should be 1 I need it to be a continuous signal, each wave with random period and pulse width
so basically i need a row of 1s followed by a row of 0s followed by a new random row of 1s and so on...
I have the signal building toolbox, don't know if this helps
Thank you

Answers (1)

It'll be something like this,
T=5*randn+45; %duration
W=5*randn+25; %pulse width
t=linspace(0,T,1000);
pulse=(t<=W);
plot(t,pulse); ylim([-1,2]);

5 Comments

Thank you, but that is not what i meant...
to make it more clear, what i´m searching for is a wave like... 1111100011111110001111100111111000111111100... so a random number of 1s, length between 4 and 6, followed by a random number of 0s, length between 2 and 3
so the numbers must be absolute and independent from the length of the whole vector, also each wave must be random in duration and pulse width
i hope, it's easier to understand now
Well, I think that's pretty much what you get if you wrap my code in a for loop. What about this, for generating a pulse train
numpulses=10;
Pcell=cell(1,numpulses);
dt=.001;
for i=1:numpulses
T=5*randn+45; %duration
W=5*randn+25; %pulse width
t=0:dt:T;
Pcell{i}=(t<=W);
end
pulse=[Pcell{:}];
t=(0:length(pulse)-1)*dt;
plot(t,pulse) ; ylim([-1 2])
How can I use the above code to fed it as a gate pulse to a converter in simulink?

Sign in to comment.

Asked:

on 1 Jul 2013

Edited:

on 30 May 2022

Community Treasure Hunt

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

Start Hunting!