The “Dirac delta function” δ(x) is a mathematical distribution and not a regular function. It is zero everywhere except at a single point, where it is infinitely large, with a total area of 1. Because of this, it can't be plotted directly using MATLAB, which rely on finite, continuous values.
MATLAB’s “dirac” function is symbolic and meant for analytical use, not visualization. When evaluated numerically, it returns zero almost everywhere and infinity at the singularity, making it unsuitable for plotting.
To visualize it, a “narrow Gaussian function” can be used as an approximation. It is mimics the delta function at a small width in a way that can be plotted and understood visually. The approximation can be taken as below:
Where:
- a is the center (e.g., 475 or -475),
- σ is a small number, controlling the width of the peak.
Below is a sample code snippet representing the plotting of a narrow Gaussian function to mimic the behaviour of a Delta function:
delta_approx = @(x, center, width) (1 / (width * sqrt(2 * pi))) * exp(-0.5 * ((x - center) / width).^2);
y = (1/4) * (delta_approx(f, 475, 0.1) + delta_approx(f, -475, 0.1));
plot(f, y, 'LineWidth', 2);
The figure obtained using the above code is as below:
Here, we can see that is behaviour is same as that of a Dirac Delta function plotted along these points.
For more information, refer to the following documentations: