# rectangularPulse

Rectangular pulse function

## Syntax

``r = rectangularPulse(a,b,x)``
``r = rectangularPulse(x)``

## Description

example

````r = rectangularPulse(a,b,x)` returns the Rectangular Pulse Function.```

example

````r = rectangularPulse(x)` is the same as `rectangularPulse(-1/2,1/2,x)`.```

## Examples

collapse all

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 =  $\left(\begin{array}{ccccc}0& \frac{1}{2}& 1& \frac{1}{2}& 0\end{array}\right)$```

Plot the rectangular pulse function using `fplot`.

```syms x fplot(rectangularPulse(x), [-1 1])```

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 =  $\frac{1}{2}$```
`r = rectangularPulse(a,b,b)`
```r =  $\frac{1}{2}$```

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 = $0$`

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 =  $\frac{1}{2}$```
`r = rectangularPulse(a,b,b)`
```r =  $\frac{1}{2}$```

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 = $1$`
`r = rectangularPulse(a,b,b)`
`r = $1$`

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');`

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 = $\mathrm{heaviside}\left(-x\right)$`
`r = rectangularPulse(0,Inf,x)`
`r = $\mathrm{heaviside}\left(x\right)$`

## Input Arguments

collapse all

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.

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.

Input coordinates, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

collapse all

### Rectangular Pulse Function

• The rectangular pulse function returns 1 if the input coordinates `x` are within the specified interval range ```a < x < b```.

• The rectangular pulse function, by default, returns ½ at the edges of the specified interval where `x = a` or `x = b` (`a` must not equal to `b`). To change the default value of the rectangular pulse at the edges, you can use `sympref`. 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

• If `a` and `b` are variables or expressions with variables, `rectangularPulse` assumes that `a < b`. If `a` and `b` are numerical values, such that `a > b`, `rectangularPulse` throws an error.

• If `a = b`, `rectangularPulse` returns 0.

## Version History

Introduced in R2012b