rectangular basis function/ rectangular pulse
6 views (last 30 days)
Show older comments
How do I create a function that is 1 over a certain period and 0 everywhere else. For example:
I need to integrate over a line split into segments and than x values are the midpoints of these segments. I have already done this by writing I = 1:N; X = delta*(I-0.5); where delta is the width of each segment. So i need to create a function that is 1 from X(i)-delta/2 <= X(i) <= X(i)+delta/2 but 0 everywhere else and be able to multiply this by an Amplitude function so that the Amplitude is the height of the pulse I am trying to create.
Any help would be much appreciated (its a Method of Moments EM problem if that helps)
1 Comment
Jarrod Rivituso
on 7 Apr 2011
Can you comment a bit more on exactly the output that you want? You state that you want to multiply this by "an amplitude function" and that you want to "create a function that is 1 from...". Do you really want to create a MATLAB function, or are you trying to create other vectors?
Answers (2)
Matt Fig
on 7 Apr 2011
Your description is a little unclear. Here is a function which will do something similar to what your first sentence asks.
function Y = squarepulse(X,center,delta)
Y = ones(size(X));
idx = X<(center-delta) | X>(center+delta);
Y(idx) = 0;
Now from the command line:
x = -10:.01:10; center = 5; delta = .5;
plot(x,squarepulse(x,center,delta))
axis([-15 15 -1 2])
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!