tags:

views:

106

answers:

4

I have a randomly generated vector, say A of length M.

Say:

A = rand(M,1)

And I also have a function, X(k) = sin(2*pi*k).

How would I find Y(k) which is summation of A(l)*X(k-l) as l goes from 0 to M?

Assume any value of k... But the answer should be summation of all M+1 terms.

+1  A: 

Given M and k, this is how you can perform your summation:

A = rand(M+1,1);            %# Create M+1 random values
Y = sin(2*pi*(k-(0:M)))*A;  %# Use a matrix multiply to perform the summation

EDIT: You could even create a function for Y that takes k and A as arguments:

Y = @(k,A) sin(2*pi*(k+1-(1:numel(A))))*A;  %# An anonymous function
result = Y(k,A);                            %# Call the function Y
gnovice
A: 
A = rand(1, M + 1);
X = sin(2 * pi * (k - (0 : M)));
total = sum(A .* X);
Geoff
A: 

This should almost certainly be tagged homework. But if you're trying to do a fourier transform, you should also look at fft.

Marc
A: 

You may be looking for the convolution of the vectors A and X:

Y = conv(A, X);
Aditya Sengupta
The output `Y` in that case would be a vector of length `2*M+1`, instead of a single value like the OP is looking for. I think one of the values in the vector will be the desired value (the middle value `Y(M+1)`), but there's no sense in computing all the other values too.
gnovice
Ah- I sensed some ambiguity when the OP mentioned "Assume any value of k", which is why I mentioned that he/she 'may' be looking for the convolution :-)
Aditya Sengupta

related questions