How to plot this delta function?

10 visualizaciones (últimos 30 días)
yiannks kkukk
yiannks kkukk el 30 de Abr. de 2021
Respondida: Vedant Shah el 30 de Mayo de 2025
Hi there, I've been having trouble plotting the following delta function, does anyone know what I should input?
Any help would be greatly appreciated.

Respuestas (1)

Vedant Shah
Vedant Shah el 30 de Mayo de 2025
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 functioncan 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 approximation using a narrow Gaussian
delta_approx = @(x, center, width) (1 / (width * sqrt(2 * pi))) * exp(-0.5 * ((x - center) / width).^2);
% Defining the function
y = (1/4) * (delta_approx(f, 475, 0.1) + delta_approx(f, -475, 0.1));
% Plot
plot(f, y, 'LineWidth', 2);
xlabel('Frequency (f)');
ylabel('Amplitude');
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:

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by