0

I need to calculate convolution of functions:
f(x)=1 when -1< x <2, 0 otherwise
g(x)=sgn(x)*dirac(abs(x)-1)

I've got this code:

Fs=1;
t=-10:1/Fs:10;
d=dirac(abs(t)-1);
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');
disp(spl);

But what I get is a lot of NaN values.
Where is my mistake? What should I change?

3
  • 1
    The question seems to be asking about a dirac delta, in continuous time—an infinitely tall and infinitely thin function—which is an analytical concept that doesn’t translate well into discrete time for solving with Matlab. Unless this is specifically a discrete-time problem, I suggest solving this analytically, or symbolically with a computer algebra system? Commented Jan 15, 2017 at 12:04
  • I've already solved this problem analytically. What i need to do now is to solve it with matlab someway. Commented Jan 15, 2017 at 12:17
  • It seems you are trying to carry out the convolution using the symbolic library. However, the symbolic library has no conv function, conv is for discrete numerical convolution. If you want to verify your integration, rewrite the convolution as an integral and use the function int for symbolic integration. Commented Jan 15, 2017 at 15:37

2 Answers 2

1

The following is a way of estimating the solution in discrete-time domain. This requires a couple of changes to your code:

  1. Increase the sample rate Fs to preserve more bandwidth. I used 100x below.

  2. Replace Dirac delta function by Kronecker delta to enable discrete-time modeling.

The modified code and the results are as follows:

Fs=100; % use higher sampling rate
t=-10:1/Fs:10;
d=(abs(t)-1)==0; % use kronecker delta function for discrete-time simulation
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');

% plots to visualize the results
figure;
subplot(3,1,1);
plot(t, x2);
ylabel('f(x)');
subplot(3,1,2);
plot(t, x);
ylabel('g(x)');
subplot(3,1,3);
plot(t, spl);
xlabel('Time');
ylabel('convolution');

results

Sign up to request clarification or add additional context in comments.

Comments

1

Try this code:

Fs=1;
t=-10:1/Fs:10;
g=t;
g(g~=1)=0;  %g function
s=sign(t);
x=g.*s;
f=t;
f(f>-1 & f<2)=1;
f(f~=1)=0;  %f function
x2=f;
spl=conv(x,x2,'same');
disp(spl)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.