# MATLAB Dirac Delta Function

Ammar Ali May 16, 2021

This tutorial will discuss how to plot the `dirac` function using the `plot()`, `stem()` and `dirac()` function in MATLAB.

## Plotting the `dirac` Function Using the `plot()`, `stem()` and `dirac()` Function in MATLAB

Dirac function is a function whose value is infinite at zero input and zero at all the other input values. We cannot plot an infinite value, so we have to give it a finite value and then plot it using the `plot()` or `stem()` function in MATLAB. The `plot()` function will show a continuous plot, whereas the `stem()` function will show a discrete plot. To create a `dirac` function, you can create it manually or using the `dirac()` function. For example, let’s create a `dirac` function and plot it using the `plot()` function. See the code below.

``````t = -5:0.1:5;
d = double(t==0);
plot(t,d)
``````

Output: In the above code, we use the `double()` function to define the value at `t==0` as one, and every other value will be zero. You can also plot the `dirac` function using `stem()` for a discrete plot.

Author: Ammar Ali

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.