필터 지우기
필터 지우기

Problem in plotting the convolution

조회 수: 2 (최근 30일)
Abdullah Alasfour
Abdullah Alasfour 2023년 7월 19일
댓글: Paul 2023년 7월 28일
I can't plot the convolution of the two signals and I don't know why
dt= 0.0001;
t = 0:dt:10;
xt = 4*cos(2*pi*730*t) +3*cos(2*pi*440*t) + 5*cos(2*pi*490*t);
subplot(2,2,1)
plot(t,xt)
axis([ 0 0.02 -20 20 ])
title(' Ploting x(t)')
xlabel('time')
ylabel('x(t)')
grid on
ht= abs( (1/2*pi*j*t).*( exp(j*1460*pi*t) - exp(j*1450*pi*t)) );
subplot(2,2, 2)
plot(t,ht)
title(' plotting h(t)')
axis( [0 20 0 70] )
xlabel(' Time')
ylabel(' h(t)')
grid on
yt= conv(xt , ht);
subplot(2,2, 3)
plot(t,yt)
title(' plotting y(t)')
axis( [0 20 0 100] )
xlabel(' Time')
ylabel(' y(t)')
grid on

채택된 답변

Star Strider
Star Strider 2023년 7월 19일
Use the 'same' argument so that the output is the same size as the input:
yt= conv(xt , ht, 'same');
This works —
dt= 0.0001;
t = 0:dt:10;
xt = 4*cos(2*pi*730*t) +3*cos(2*pi*440*t) + 5*cos(2*pi*490*t);
subplot(2,2,1)
plot(t,xt)
axis([ 0 0.02 -20 20 ])
title(' Ploting x(t)')
xlabel('time')
ylabel('x(t)')
grid on
ht= abs( (1/2*pi*j*t).*( exp(j*1460*pi*t) - exp(j*1450*pi*t)) );
subplot(2,2, 2)
plot(t,ht)
title(' plotting h(t)')
axis( [0 20 0 70] )
xlabel(' Time')
ylabel(' h(t)')
grid on
yt= conv(xt , ht, 'same');
subplot(2,2, 3)
plot(t,yt)
title(' plotting y(t)')
axis( [0 20 0 100] )
xlabel(' Time')
ylabel(' y(t)')
grid on
.
  댓글 수: 4
Abdullah Alasfour
Abdullah Alasfour 2023년 7월 19일
Sure and have a great day
Star Strider
Star Strider 2023년 7월 19일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2023년 7월 19일
편집: Paul 2023년 7월 19일
Hi Abdullah,
Although not stated explicitly in the Question, I'm going to assume that
a) the objective is compute the convolution integral, i.e., xt and ht are continuous time signals, and
b) xt and ht are both zero for t < 0 adn t > 10
If those assumptions are correct, here's a similar problem that shows how to use conv to approximate the convolution integral. Maybe you can adapt it to your problem.
Let's use two simple functions for x(t) and h(t), both of which are zero outside the interval 0 <= t <= 3
syms t real
x(t) = exp(-0.2*t)*rectangularPulse(0,3,t);
h(t) = exp(-0.3*t)*rectangularPulse(0,3,t);
By defintion, the convolution integral for these signals is
syms tau real
y(t) = simplify(int(x(tau)*h(t-tau),tau,0,t))
y(t) = 
Plot x(t), h(t), and y(t). The duration of y(t) (6 seconds) is the sum of the durations of x(t) and h(t).
fplot([x(t) h(t) y(t)],[0 7])
Now use conv with numerical valuse of x(t) and h(t) sampled at 0.01 seconds
t = 0:.01:3;
x = exp(-0.2*t);
h = exp(-0.3*t);
To get the correct answer, we need to use the full convolution and multiply the result by the sampling period (because both x(t) and h(t) are finite)
y = conv(x,h,'full')*0.01; % 'full' is the default, so not necessary to specify explicitly
Of course, y will be longer than x and h, so we have to define a new time vector to plot it.
hold on
plot((0:numel(y)-1)*0.01,y)
For this problem, if we use the 'same' convolution, we get a y that has the same number of elements x and h and therefore covers 3 seconds. But that that's not sufficient to approximate the 6-second convolution integral. And we can see that plotting it would require a shift to the right by 1.5 seconds to match up with the "central" part of the convolution integral.
y = conv(x,h,'same')*0.01;
plot(t,y)
legend('x(t)','h(t)','y(t)','yconv-full','yconv-same')
  댓글 수: 2
Image Analyst
Image Analyst 2023년 7월 28일
He's using Octave, not MATLAB.
Paul
Paul 2023년 7월 28일
I didn't notice the Octave tag because I don't look at the tags.
I'm also not sure about how to interpret this comment.
Are questions tagged with "octave" not supposed to be answered? Should they be closed?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by