How to plot the results of conv?

6 views (last 30 days)
Kristin
Kristin on 10 Mar 2014
Edited: Patrik Ek on 10 Mar 2014
Hi,
I need to do a convolution between two distributions, such as A and B, to this I have considered using conv. But when the values (x-axis) of the two distributions are different, I have problems interpreting the results. If I convolve A and B, what x-values do I have to plot the results against? Or should I use something other than conv in this case?
For example, which of the dashed curves in this figure is the correct one?
----------------------------------------------------------------------
clear all; close all; clc
% Distribution A
x_A = [-10:0.5:10]; y_A = normpdf(x_A,2,0.5);
% Distribution B
x_B = [-9:5]; y_B = [0 0 0 0.05 0.1 0.15 0.22 0.31 0.4 0.5 0.7 0 0 0 0];
% Convolution of distributions
conv_AB = conv(y_A,y_B,'same'); conv_BA = conv(y_B,y_A,'same');
figure(1)
plot(x_A,y_A,'k')
hold on
plot(x_B,y_B,'b')
hold on
plot(x_A,conv_AB,':k')
hold on
plot(x_B,conv_BA,':b')
legend('A','B','conv AB - A scale','conv BA - B scale')
----------------------------------------------------------------------
Best regards, Kristin

Accepted Answer

Patrik Ek
Patrik Ek on 10 Mar 2014
Edited: Patrik Ek on 10 Mar 2014
Are you sure any of the curves are correct? It seems a bit strange that both curves peaks when one or both of the distributions are almost zero. Furthermore I would say uniform sampling is important, when using conv, which calculates an estimate of the convolution in the simplest way,
y(k) = \sum^N_{n=k}(x(n).*g(n-k)); (1)
(if you excuse the pseudo latex and matlab code please send a comment if this is unclear). This assumes that the sampling points are the same in the two vectors x and g. If not this would mean that the point n in x would not correspond to the point n-k in g.
Also, assume that the distributions are not even uniformely sampled! This would indeed introduce another issue. The fundamental implementation of the convolution from (1) assumes uniform sampling. That is why conv only have 2 input arguments, in this case x and g. Think that these are implemented as in (1). Even if the input points in x correspond to the right point in g the densest sampled sections would be weighted heavier. This means that some values get a higher importance than others, given the sampling rate in this section. This is not correct since the weight of each sample should only depend on the distance from its current location ( k = 0 ). So to say, irregular sampling and different samplig points are not simple to handle this case should be avoided to the largest possible extent. However, if you still need to use it, you should dig into some theory regarding irregular sampling.
PS: The bold fond is not yelling, only marking out some important key words.
EDIT:
This assumes that the sampling points are the same in the two vectors x and g of course. Sorry if I cause confusion
/BR Patrik
  1 Comment
Kristin
Kristin on 10 Mar 2014
Thank you for taking the time to answer my question! I'm not at all sure that any of the curves is correct, I agree that it looks strange. I think I understand the problem you describe, I will try to investigate further how it can be solved.
Best regards Kristin

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!