Basic questions on conv function
Mostra commenti meno recenti
Hi,
Suppose I have the following code:
t=(-1:.1:5); %Time axis
for i=1:1:length(t);
if t(i)<0
a=0;
h(i)= 0;
f(i) = 0;
else
a=1;
h(i) = a.*exp(-2.*t(i));
f(i) = a.*exp(-t(i)./2);
end
end
u=conv(f,h,'same')*.1;
plot(t,h,t,f,t,u1)
I'm just trying to plot the convolution of these two basic functions. When I look at examples people just use conv and plot the data along with the original functions. But it doesn't seem that easy, the convolution set is larger than the original dataset, and it's shifted. By shifted I mean the plot of conv vs. t has amplitude before t=0. How does one correct for such things to display the functions and the convolution on the same graph?
Thanks a lot, Charles
3 Commenti
Angus
il 25 Giu 2013
Hey, not familiar myself with this topic but it seems interesting, I found an example that, while a bit long, might be helpful. Here as a PDF and here as a .m file. It seems that you should expect the convolution to have a larger range than either of the two functions individually.
If I come to understand this more I'll let you know, likewise I would be interested if you figure it out.
Cheers, Angus.
Angus
il 25 Giu 2013
Also this explanation and example might be helpful. The example at the end is similar to what you are doing.
Cheers
Senaasa
il 25 Giu 2013
Risposta accettata
Più risposte (3)
Image Analyst
il 26 Giu 2013
0 voti
You need to understand both what it's doing, and what you want. If you don't want data where the kernel is not completely overlapped with the main signal, then you can use the 'valid' option. If you want it to end when it's half overlapped, use the 'same' option. Most often I use the 'same' option because I want the data the same size as the original and don't really care too much what happens out near the edges. If you want the full convolution then you have to realize that the index no longer corresponds to the same part of the signal as the same number index did in the original signal. So if you're plotting, you have to take that into account.
1 Commento
Senaasa
il 26 Giu 2013
Categorie
Scopri di più su Correlation and Convolution in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!