Convolution of two matrixes of PDF values

4 次查看(过去 30 天)
Hello,
I'm trying to write a function that looks like something like this: convolved_matrix = convolve_matrixes(matrix1, matrix2), where the matrixes are N x 2 large (N rows and 2 columns). These matrixes is containing PDF values where on the first column contains the indexes and the second column contains the probabilities. So my question is how can i obtain a matrix that contains the correct convolution with correct index values and probability values between the inputed matrixes?
  1 个评论
John D'Errico
John D'Errico 2024-5-2
Is the first column a set of equally spaced values? Or are they scattered, unequally spaced? The answer would be hugely different depending on your response.

请先登录,再进行评论。

回答(1 个)

Balavignesh
Balavignesh 2024-5-20
Hi Daniel,
It is my understanding that you wish to find the convolution of two matrices containing probability distribution values. The convolution of two probability distributions represents the probability distribution of the sum of two independent random variables represented by these distributions.
Assuming your matrices are properly structured with indices and probabilities, the convolution process will involve calculating the sum of all possible pairs of indices and their corresponding products of probabilities. The resulting convolved matrix will have its indices ranging from the sum of the minimum indices to the sum of the maximum indices of the input matrices. Additionally, the probabilities will be the sum of the products of probabilities for each pair of indices that sum to a given index.
Have a look at the following code snippet to better understand this:
% Dummy Matrices
matrix1 = [1 0.2; 2 0.5; 3 0.3];
matrix2 = [1 0.4; 2 0.6];
% Extract indices and probabilities from the input matrices
indices1 = matrix1(:, 1);
probs1 = matrix1(:, 2);
indices2 = matrix2(:, 1);
probs2 = matrix2(:, 2);
% Calculate the range of the convolved indices
minIndex = min(indices1) + min(indices2);
maxIndex = max(indices1) + max(indices2);
convolvedIndices = (minIndex:maxIndex)';
% Initialize the convolved probabilities vector
convolvedProbs = zeros(length(convolvedIndices), 1);
% Perform the convolution operation
for i = 1:length(indices1)
for j = 1:length(indices2)
% Find the convolved index for the current pair of indices
convolvedIndex = indices1(i) + indices2(j);
% Find the position of this index in the convolvedIndices array
position = convolvedIndex - minIndex + 1;
% Add the product of the probabilities to the corresponding position
convolvedProbs(position) = convolvedProbs(position) + probs1(i) * probs2(j);
end
end
% Combine the convolved indices and probabilities into the output matrix
convolvedMatrix = [convolvedIndices, convolvedProbs];
disp(convolvedMatrix)
2.0000 0.0800 3.0000 0.3200 4.0000 0.4200 5.0000 0.1800
You might find the below documentation link useful:
Hope that helps!
Balavignesh

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by