Plot convolution of two wave signals

조회 수: 28 (최근 30일)
Hessa Alhajri
Hessa Alhajri 2021년 4월 23일
편집: Paul 2021년 4월 24일
i want to plot the convolution of x=cos(wt) with frequency=10^6 and c=0.5(1+square(wt)) with freequency=10^5
i tried with the code below but convolution signal graph wasn't appear
>> fs=10^6;
>> T=1/fs;
>> tt=0:T/100:30*T;
>> m=cos(2*pi*fs*tt);
>> plot(tt,m)
>> fc=10^5;
>> c=0.5*(1+square(2*pi*fc*tt));
>> y=conv(m,c);
>> plot(tt,y)
Error using plot
Vectors must be the same length.
>> t1=0:0.01:10;
>> plot(t1,y)
Error using plot
Vectors must be the same length.

채택된 답변

DGM
DGM 2021년 4월 23일
편집: DGM 2021년 4월 23일
The length of the result of convolving two vectors is the sum of the vector lengths. Try this:
fs=10^6;
T=1/fs;
tt=0:T/100:30*T;
m=cos(2*pi*fs*tt);
fc=10^5;
c=0.5*(1+square(2*pi*fc*tt));
y=conv(m,c,'same'); % conv and conv2 return the full convolution by default
subplot(3,1,1)
plot(tt,m)
subplot(3,1,2)
plot(tt,c)
subplot(3,1,3)
plot(tt,y)

추가 답변 (1개)

Paul
Paul 2021년 4월 24일
편집: Paul 2021년 4월 24일
If we assume that m(t) = c(t) = 0 for t < 0, we can show analytically that the convolution integral m(t)*c(t) is periodic with period 1/fc, and one period is
p(t) = (sin(2*pi*fs*t)/(2*pi*fs) , t < (1/(2*fc)
p(t) = 0, 1/(2*fc) < t < 1/fc
When approximating the convlution integral with the convolution sum, don't forget to scale the sum by dt. Here is the code, extending the time vector furher out
fs=10^6;
T=1/fs;
tt=0:T/100:60*T;
m=cos(2*pi*fs*tt);
fc=10^5;
c=0.5*(1+square(2*pi*fc*tt));
yy=conv(m,c)*tt(2); % multiply by dt!
% analytic solution
pfunc = @(t) (sin(2*pi*fs*mod(t,1/fc))/(2*pi*fs).*(mod(t,1/fc) < 1/2/fc));
plot(tt,yy(1:numel(tt)),tt,pfunc(tt))
As you can see, the approximating convolution sum isn't quite accurate and becomes less so as t increases. I'm not exactly sure why that is, some sort of round-off accumulation perhaps?

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by