Reputation: 7995
I am struggling with declaring some more complex matrices in matlab, perhaps you could help me out, I have an array of $T$ values / lets call it $y = [y_0, \hdots, y_T]$ (its a digital signal representing a sound).
I am using formula:
\begin{equation}
y_t= a_0 + \sum_{i=1}^p (a_i y_{t-i} + \epsilon_t), t \geq p,
\end{equation}
in order to create a synthetic signal based on the one give using only previous $p$ values of $y_t$, where $p$ is significantly smaller than y. What I have to do, is find those $a_0, \vdots, a_p$ parametres in order to use LSE method.
Now here is what I need you guys to help me with: How do I create a matrix that looks like this:
\begin{equation}
M =
\begin{bmatrix}
1 & 0 & 0 & 0 & 0 & \hdots & 0 \\
1 & y_0 & 0 & 0 & 0 & \hdots & 0 \\
1 & y_1 & y_0 & 0 & 0 & \hdots & 0 \\
1 & y_2 & y_1 & y_0 & 0 & \hdots & 0 \\
\vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
1 & y_{T-1} & y_{T-2} & \hdots & \hdots & \hdots & y_{T-p} \\
\end{bmatrix}
\in R^{T+1xp+1}
\end{equation}
Thanks for any help
edit: how to format LaTeX here?
Upvotes: 0
Views: 604
Reputation: 6071
You seem to need a matrix that represents a sort of convolution. In Matlab the toeplitz function is relevant here.
See the following example
>> y=[1 2 3 4 5 6 7];
>> toeplitz(y,[y(1) zeros(1,length(y)-1)])
ans =
1 0 0 0 0 0 0
2 1 0 0 0 0 0
3 2 1 0 0 0 0
4 3 2 1 0 0 0
5 4 3 2 1 0 0
6 5 4 3 2 1 0
7 6 5 4 3 2 1
So your code should look like the follwing
M = [ones(length(y),1) toeplitz(y,[y(1) zeros(1,length(y)-1)]) ];
M = M(:,1:p+1);
Upvotes: 2
Reputation: 45741
It's really hard to see what's going on because of the formatting of the quesiton but how about this:
M = zeros(length(y) + 1);
M(1) = 1;
for row = 2:length(y)+1
M(1:row) = [1 y(row-1:-1:1)];
end
Upvotes: 0