Fourier transform using Convolution
4 views (last 30 days)
Show older comments
I have two signals x(t) = sin(2.*pi.*t)/(pi.*t) and y(t) = x(t) I want to calculate z(t) = x(t)*y(t) and z(JW).I should plot x(t), x(JW), y(t), y(JW) and z(t), z(JW) using subplot. z(JW)=(1/(2pi))*(convolution(x(t),y(t))), I have the following code:w = [-6.*pi 6.*pi];
syms x(t)
x(t) = sin(2.*pi.*t)./(pi.*t);
subplot(3,2,1)
fplot(t,x(t));
title('x(t) vs t');
xlabel('time');
ylabel('x(t)')
X_J_W = fourier(x(t));
subplot(3,2,2)
fplot(X_J_W,w);
title('X(JW) vs w')
ylabel('X(JW)')
xlabel('W')
syms y(t)
y(t) = sin(2.*pi.*t)./(pi.*t);
subplot(3,2,3)
fplot(t,y(t));
title('y(t) vs t');
xlabel('time');
ylabel('y(t)')
Y_J_W = fourier(y(t));
subplot(3,2,4)
fplot(Y_J_W,w);
title('Y(JW) vs w')
ylabel('Y(JW)')
xlabel('W')
syms z(t)
z(t) = x(t).*y(t);
subplot(3,2,5)
fplot(z(t));
C_X_Y = conv(X_J_W,Y_J_W,'full');
Z_J_W = (1./(2.*pi)*(C_X_Y));
subplot(3,2,6)
fplot(Z_J_W,w)
in the convolution part I get
Error using conv2
Invalid data type. First and second arguments must be numeric or logical.
Error in conv (line 43)
c = conv2(a(:),b(:),shape);
and I do not know how to fix it.
0 Comments
Answers (1)
Matt J
on 23 Dec 2020
You must use int to implement a symbolic convolution integral. conv is for numeric convolution.
12 Comments
Matt J
on 24 Dec 2020
Truncating the convolution seems to help:
syms x(t) y(t) z(t) c(t) X(w) Y(w) tau
x(t) = sin(2.*pi.*t)./(pi.*t);
y(t) = sin(2.*pi.*t)./(pi.*t);
z(t)=x(t).*y(t);
X(w) = fourier(x(t));
Y(w) = fourier(y(t));
c(t)=int(x(tau).*y(t-tau),tau,-100,+100);
fplot(c(t))
Paul
on 24 Dec 2020
Edited: Paul
on 24 Dec 2020
Nurhan,
Why compute the convolution of x(t) and y(t)? I thought the problem at hand is related to the product of x(t) and y(t).
If z(t) = x(t)y(t), then
Z(w) = conv(X(w),Y(w))/2/pi:
>> syms u
>> Z(w)=int(X(u)*Y(w-u),u,-inf,inf)/2/pi;
>> Z(w)
ans =
-((heaviside(- w - 4*pi)*(w + 4*pi))/2 - w*heaviside(-w) + (heaviside(4*pi - w)*(w - 4*pi))/2)/pi
>> fplot(Z(w),[-20 20])
The result can be confirmed by numerically computing the Fourier transform of z(t):
>> fun=matlabFunction(z(t)*exp(-1j*w*t));
>> wr=-20:.1:20;
>> for ii=1:numel(wr),q(ii)=integral(@(t)fun(t,wr(ii)),-20,20);end
>> hold on
>> plot(wr,real(q),'ro'),grid
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!