How do you add specific elements contained within a matrix to produce a new vector?

I have the columns of n, x[n], and h[n] already produced. Now what I want to produce is the column w[n]. (Side question: is "column" correct term to be using in this instance? Or is "vertical array" or "vector" more appropriate?)

To avoid wasting your time, I've simplified the structure of w[n] in the little box there on the right-hand side, which reads: "In general, the corresponding element of w[n] meets these criteria: 1. has n+1 "component pairs", and 2. those "components pairs" are such that h[k]*x[m] where k+m=n.

Ex1. n=0. w[0] has one (0+1) "component pair:" h[0]*x[0] where k+m=0. Ex2. n=1. w[1] has two (1+1) "component pairs:" h[0]*x[1]+h[1]*x[0] where each k+m=1=n.

And in case you've now forgotten the question: How do I produce w[n] by manipulating the elements in x[n] and h[n].

 Réponse acceptée

That's known as convolution, and you can use matlab's 'conv' function to do the required computation.
w = conv(x,h);
w = w(1:n+1);
Note: Zero indices are not allowed in matlab so the indices shown in your image will have to be increased by one. The first element is w(1) = x(1)*h(1), and the second element would be w(2) = x(1)*h(2)+x(2)*h(1), and so forth.

5 commentaires

Roger, thank you. The 'conv' command worked perfectly... except for one thing. It output 40 extra values so that I now have a 81x1 array instead of a 41x1 array.
I do not believe this to mere coincidence that I have 40 extra rows and my values of n are 0-40. what are your thoughts on why this convolution produced 40 extra values?
@James Long: have a look at conv's third optional argument shape, and try each of them until you get the desired output.
visiting the reference page for 'conv' I see that by adding 'same' within the conv command, it will yield and array with the dimensions I am after, however the values inside change when applying this phrase ('same') within the conv command. Ideally, I would chop off the last 40 values in my output to yield a 41x1 array and call it a day.
i just did wn(42:81)=[]; and it worked. thank you for your assistance Roger and Stephen.
@James: That's what the line "w = w(1:n+1);" was meant to accomplish!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by