Fourier transform using Convolution
이전 댓글 표시
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.
답변 (1개)
Matt J
2020년 12월 23일
0 개 추천
You must use int to implement a symbolic convolution integral. conv is for numeric convolution.
댓글 수: 12
Nurhan Aydinalp
2020년 12월 23일
Nurhan Aydinalp
2020년 12월 23일
Matt J
2020년 12월 23일
I'm not sure why we are talking about converting functions to integers. A convolution is an integral. You can use the Symbolic Toolbox's int() command to implement it,
Nurhan Aydinalp
2020년 12월 23일
Matt J
2020년 12월 23일
We can't see what you did ...
Nurhan Aydinalp
2020년 12월 23일
Paul
2020년 12월 23일
Code as posted results in Z_J_W being a function of both t and tao, at least when I run it in 2019A. Hence fplot doesn't know which variable to plot against or what value to assume for the other.
I think that the expression for C_X_Y is not correct. I think it's integrating from tao to t wrt to t, when it should be integration from 0 to t wrt tao (also, see comment below). I think this would be the correct syntax for the integration and to make C_X_Y a function:
C_X_Y(t) = int(x(tao).*y(t-tao),tao,0,t);
However, when I run this I don't get a nice closed form expression for C_X_Y.
Similarly, you probably want
X_J_W(w) = fourier(x(t));
and the same for Y_J_W.
z(t) is coded as the product of x(t) and y(t). Then Z_J_W is coded as some scaled value of the convolution of x(t) and y(t), which doesn't really follow assuming that Z_J_W is supposed to be the Fourier transform of z(t).
Looking back at your original question, it's not clear what you're trying to do.
Is z(t) the convolution of x(t) and y(t)? In which case Z_J_W = X_J_W * Y_J_W
Or is z(t) the the product of x(t) and y(t)? in which case Z_J_w = (1/2/pi)*convolution(X_J_W(w),Y_J_W(w))
The expression for the convolution of x(t) and y(t) implies that both are zero for t < 0. But x(t) and y(t) are not defined that way, so the call to fourier just assumes that x(t) and y(t) are nonzero for t < 0.
Nurhan Aydinalp
2020년 12월 24일
Seems alright to me:
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,-inf,+inf) %convolution of x and y
Nurhan Aydinalp
2020년 12월 24일
편집: Nurhan Aydinalp
2020년 12월 24일
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))
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
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

