Plot convolution of two wave signals

19 次查看(过去 30 天)
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