MATLAB waveform question

Status
Not open for further replies.

W_Heisenberg

Full Member level 4
Joined
Feb 27, 2011
Messages
217
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Location
Boston
Activity points
2,575
Hi, I need to make a unit step function , a triangle function, a rectangle function. And plot these by stem.
How can I do that in MatLab?

anyone helps?
 

In my limited experience with Matlab, I find concatenating data to form a complex waveform easier then trying to generate all of it in one step. Hope this helps a little.
 

the thing is that hard to write any for loop to achieve this...

even for a single step function... this is due to matlab matrix index maybe
 

I'm not sure if that code will work or not but worth a try for a step function in the interval (-5, 5).

Code:
i= -10: 1:10;
s= (i>= 0);

For the triangle generating a ramp with positive and negative aims and then concatenating them may work.

Code:
m= 3; % aim
i= 0: 1: 10;
t1= 3*i;
t2= -3*i;
t=[t1, t2];

For rectangle again concatenating step functions may work. There was also the 'rectpuls' function that was generating some kind of a rectangle signal but not sure how it works.
Code:
r= 0;
for i=1: 1: 10
     r= [r s];
end

Again those are what I came up with my limited experience, there must be much better ways to achieve those.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…