Plot convolution of two wave signals

31 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by