Plot convolution of two wave signals

19 vues (au cours des 30 derniers jours)
Hessa Alhajri
Hessa Alhajri le 23 Avr 2021
Modifié(e) : Paul le 24 Avr 2021
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.

Réponse acceptée

DGM
DGM le 23 Avr 2021
Modifié(e) : DGM le 23 Avr 2021
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)

Plus de réponses (1)

Paul
Paul le 24 Avr 2021
Modifié(e) : Paul le 24 Avr 2021
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?

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by