Medulla Oblongata
Medulla Oblongata

Reputation: 3961

Multiple convolutions in Matlab

I want to numerically calculate several convolutions like

where the x, y, z, w functions are given in the below code:

t = linspace(-100,100,10000);

x = t.*exp(-t.^2);
y = exp(-4*t.^2).*cos(t);
z = (t-2)/((t-2).^2+3^2);
w = exp(-3*t.^2).*exp(2i*t);

u = conv(conv(conv(x,y),z),w);

plot(t,u) % ??? - if we want to convolute N functions, what range should t span?

Is this the most efficient way to calculate and plot multiple convolutions? Is it generally better to numerically integrate the functions for each convolution?

Edit:

This is the plot of the real part of my convolution, u vs t:

whereas the method (using FFTs) suggested by a poster below gives me:

enter image description here

What causes this discrepancy?

Upvotes: 2

Views: 701

Answers (1)

KKS
KKS

Reputation: 1389

If the signal length is long, fft method would be better.

Below is an example.

t = linspace(-100,100,10000);

x = t.*exp(-t.^2);
y = exp(-4*t.^2).*cos(t);
z = (t-2)/((t-2).^2+3^2);
w = exp(-3*t.^2).*exp(2i*t);

L_x=fft(x);
L_y=fft(y);
L_z=fft(z);
L_w=fft(w);

L_u=L_x.*L_y.*L_z.*L_w; %convolution on frequency domain

u=ifft(L_u); 

figure(1)
plot(t,abs(u))
figure(2)
plot(t,real(u))
figure(3)
plot(t,imag(u))

Upvotes: 2

Related Questions