rectangularPulse
Rectangular pulse function
Description
Examples
Compute Rectangular Pulse Function
Compute the rectangular pulse function at coordinates –2, –1, 0, 1, and 2 with specified rising and falling edge at –1 and 1. Because these inputs are not symbolic objects, you get floating-point results.
r = rectangularPulse(-1,1,-2:2)
r = 1×5
0 0.5000 1.0000 0.5000 0
Compute the rectangular pulse function for the same inputs in symbolic form.
r = rectangularPulse(sym(-1),1,-2:2)
r =
Plot Rectangular Pulse Function
Plot the rectangular pulse function using fplot
.
syms x
fplot(rectangularPulse(x), [-1 1])
Edge Values of Rectangular Pulse
Show that if a < b
, the rectangular pulse function for x = a
and x = b
equals 1/2
.
syms a b x assume(a < b) r = rectangularPulse(a,b,a)
r =
r = rectangularPulse(a,b,b)
r =
For further computations, remove the assumptions on the variables a
and b
by recreating them using syms
.
syms a b
For a = b
, the rectangular pulse function returns 0
.
r = rectangularPulse(a,a,x)
r =
Change Values of Rectangular Pulse at Rising and Falling Edges
The default value of the rectangularPulse
function at the rising and falling edges is 1/2
.
syms a b assume(a < b) r = rectangularPulse(a,b,a)
r =
r = rectangularPulse(a,b,b)
r =
Another common value at these edges is 1
. To change the value of rectangularPulse
at the edges, use sympref
to set the value of the 'HeavisideAtOrigin'
preference. Store the previous parameter value returned by sympref
, so that you can restore it later.
oldparam = sympref('HeavisideAtOrigin',1);
Check the new value of rectangularPulse
at the rising and falling edges.
r = rectangularPulse(a,b,a)
r =
r = rectangularPulse(a,b,b)
r =
The preferences set by sympref
persist throughout your current and future MATLAB® sessions. To restore the previous value of rectangularPulse
at the edges, use the value stored in oldparam
.
sympref('HeavisideAtOrigin',oldparam);
Alternatively, you can restore the default value of 'HeavisideAtOrigin'
by using the 'default'
setting.
sympref('HeavisideAtOrigin','default');
Relation Between Rectangular Pulse and Heaviside Function
When the rising or falling edge of rectangularPulse
is at the infinity, then this function is the same as the Heaviside step function (the unit step function).
syms x
r = rectangularPulse(-Inf,0,x)
r =
r = rectangularPulse(0,Inf,x)
r =
Input Arguments
a
— Starting position of rectangular pulse
-1/2
(default) | number | symbolic scalar variable
Starting position of rectangular pulse, specified as a number or a symbolic scalar variable. This argument specifies the rising edge of the rectangular pulse function.
b
— Ending position of rectangular pulse
1/2
(default) | number | symbolic scalar variable
Ending position of rectangular pulse, specified as a number or a symbolic scalar variable. This argument specifies the falling edge of the rectangular pulse function.
x
— Input coordinates
number | vector | matrix | array | symbolic number | symbolic variable | symbolic array | symbolic function | symbolic expression
Input coordinates, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.
More About
Rectangular Pulse Function
The rectangular pulse function returns 1 if the input coordinates
x
are within the specified interval rangea < x < b
.The rectangular pulse function, by default, returns ½ at the edges of the specified interval where
x = a
orx = b
(a
must not equal tob
). To change the default value of the rectangular pulse at the edges, you can usesympref
. For more details, see Change Values of Rectangular Pulse at Rising and Falling Edges.Otherwise, the rectangular pulse function returns 0.
The rectangular pulse function is also known as the rectangular function, normalized boxcar function, Heaviside Pi function, or gate function.
Tips
Version History
Introduced in R2012b
See Also
dirac
| heaviside
| triangularPulse
| sympref
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)