How to generate a vector of a shifted impulse function?

Hello, Suppose we have a time vector x=0:0.1: 50. I would like to have a delta function at a non-zero position, say at 25 with unit height (or any other scaled version of it).
MATLAB has a function d = dirac(x)
It generates dirac at x=0. If we write, d=dirac(x-25), it does not shift the impulse function like the H=heaviside(t-25) translates the heaviside function at 25.
I tried differentiating the translated heaviside function but I get 0.5 0.5 at the desired location instead of 1 at 25, no matter what the sampling frequency is.
Is there are a better way to do
(a) Generate a vector unit delta at a non-zero position
(b) Differentiate translated Heaviside and get a shifted delta at the desired position.
Thanks.

 Accepted Answer

If we write, d=dirac(x-25), it does not shift the impulse function like the H=heaviside(t-25) translates the heaviside function at 25.
It does, actually.
Consider:
x = 0:0.1:50;
d = dirac(x - 25);
nzdidx = find(d>0) % Index
dnzd = d(nzdidx) % Value
producing:
nzdidx =
251
dnzd =
Inf
So it will not appear on the plot, since it has infinite amplitude and 0 width, integrating to an area of 1.
.

6 Comments

Thank you, no wonder I could not see it in a plot. How should we convert the infinity to 1 or any other scaled version of unity?
My pleasure!
Try this (following on my previous code):
d(nzdidx) = 1;
figure
stem(x, d, 'LineWidth',1)
grid
Note that this is no longer a true impulse function, although defining it with a width of 1 as well would at least satisfy the requirement that it integrates to 1.
.
Thanks, I am wondering why Heaviside is not differentiating to a height of 1, instead I get 0.5 and 0.5 instead.
As always, my pleasure!
I am not certain what you are doing.
Try this:
syms x
h = heaviside(x - 1)
dh = diff(h)
to get:
dh =
dirac(x - 1)
(I am using R2020a, although I doube that there would be any version differences.)
.
Strider, I was trying to demonstrate the effect of convolution of a Lorentzian with a shifted delta to a person. I was stumped as to how one can generate a displaced delta vector in MATLAB. Thanks for your assistance. I have MATLAB 2019b. I can download 2020 but I don't think it is worth changing.
As always, my pleasure!
As for upgrading to R2020a, see the Release Notes to see if it would be of any benefit to you. (Note that Update 4 is current.)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

FW
on 27 Jul 2020

Commented:

on 27 Jul 2020

Community Treasure Hunt

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

Start Hunting!