
Plot convolution of two wave signals
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
DGM
il 23 Apr 2021
Modificato: DGM
il 23 Apr 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)

0 Commenti
Più risposte (1)
Paul
il 24 Apr 2021
Modificato: Paul
il 24 Apr 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?
0 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!