×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to use tripuls(T,w)

How to use tripuls(T,w)

How to use tripuls(T,w)

(OP)
I need to create a triangular pulse with width of 5 samples and amplitude of one at t=1,10, 15. Please show an example.

Thanks.
 

RE: How to use tripuls(T,w)

The simple way to generate a triangle pulse is to use the triang command in the signal processing toolbox.  Also, below is a code that performs the same function as triang, with a different (hopefully clearer) algorithm.

Good Luck
J. Vorwald


function test

% Initalize time and y vector (y set to zero)

dt = 1;
t  = 0:dt:20;
y  = t*0;

% Get a the triangle shape using the width of the base

%  triSize = 6;
triSize = 5;
triShape=triang(triSize);

% insert the base at times 1.0, 10.0, and 15.0

y = insertShape(t, y, triShape, 1.0);
y = insertShape(t, y, triShape, 10.0);
y = insertShape(t, y, triShape, 15.0);
plot(t,y);

% Set the maximum y axis to one
a = axis;
a(4) = 1;  
axis(a);


function  yout = insertShape(t, y, triShape, tstart);

  % Insert the shape (triShape) at time tstart

  triSize = size(triShape,2);
  istart = find( t == tstart );
  ichange = [1:triSize] + istart -1;
  yout = y;
  yout( ichange ) = triShape;


function triangle = triang(nPoints)

%TRIANG Triangular window.
%   triangle = TRIANG(nPoints) returns the N-point triangular window.

% For a triangle, the ramp up and ramp down are the symmetric
% For a triangle
%  a) The number of points going up/down is (nPoints-1)/2
%  b) The peak ramp value is (nRamp - 1) / nRamp;
% For a triangle with an odd number of points
%  c) The triangle reaches the maximum value at the mid point, (Npoints-1)/2 + 1

% use a flag to indicate even/odd  (0 - even, 1 - odd)

flagEvenOdd = rem(nPoints,2);

nRamp = (nPoints - flagEvenOdd) / 2;

ramp = [0:nRamp-1] / nRamp;
rampUp   = ramp;
rampDown = rampUp(nRamp:-1:1);

if (flagEvenOdd == 1)
    rampUp = [rampUp 1];
end

triangle    = [ rampUp rampDown ];

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources