Need to make a square pulse w/o a special function
Mostra commenti meno recenti
hi everyone,
really stuck here, need to make a periodic square (step pulse) that turns on to a certain value at a time, and turns off again. I need to make a code for it as i cant use a prebuilt function like square etc. Preferably use for loops and if statements etc.
can someone help me
1 Commento
Saurabh Sakpal
il 3 Ago 2015
Risposta accettata
Più risposte (3)
Geoff Hayes
il 3 Ago 2015
% create an array of 10000 elements linearly spaced from 0 to 10
% (can consider this a time vector of then seconds)
t = linspace(0,10,10000);
% set the amplitude
a = 2.0;
% create the square pulse
y = (a/2)*sign(sin(2*pi*t)) + (a/2);
plot(t,y);
As the result of
sign(sin(2*pi*t))
is an array of values between -1 and +1, then in order to get the range as shown in your figure (which is the interval [0 a]) we just multiply the result by a/2 and then add a/2. Try the above and see what happens!
1 Commento
Saurabh Sakpal
il 4 Ago 2015
Saurabh Sakpal
il 4 Ago 2015
0 voti
Saurabh Sakpal
il 4 Ago 2015
0 voti
1 Commento
Star Strider
il 4 Ago 2015
What does ‘its not working’ mean? We cannot guess what you want. You must tell us as specifically as you can.
My repmat code produces a single string of 1s and 0s of whatever length and ratio you want for as many periods as you want. You can specify them individually.
To define it as a function of time, define a time vector for it. The linspace function is perfect for this.
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
