The implementation of the Dirac Delta Function is a bit tricky, as mathematically speaking it's not an ordinary function. One popular way to define the Delta Function is to use a limit of a Gaussian function, as follows:
main.m293 chars11 lines
The above code generates a normalized Gaussian function, then assigns a limit to it, making it tend to infinity while its area remains 1 (so as to keep the definition of the Delta Function).
You can plot both functions to see that the Delta Function looks much like a "spike" at the point where x=0:
main.m67 chars6 lines
Note: The length of the signal should be big enough to be able to resolve the effect of delta function. And there are more methods to generate delta function like using derivative of step function or Fourier transform etc.
gistlibby LogSnag