# How to extract two signals from one signal by selecting right index?

Assume that we want to solve

$$AX=B$$

Where both $$A, X, B$$ are matrices.

I solved this by using ordinary least squares:

$$X = (A^TA)^{-1}A^TB$$

And I got this result for one column in $$X$$.

Here we can se two inpuls signals. One large and one small. It's easy to split these two if they are indexing with the space 2 if there are 2 signals. Or space 3 if there are 3 signals.

But in this case, it's a little bit different because of this. Here we can that the red inpulse signal and green impulse signal follows the same pattern, until the purple index.

My idea was to use MATLAB and extract these signals from the columns of $$X$$, but it does not work due to index changing.

Question:

Is there a way to extract data in a better way? We know how many signals there are in the column of $$X$$.

Here is how to repeat this problem:

  % Check if u and y has the same length
if(length(u) ~= length(y))
error('Input(u) and output(y) has not the same length')
end

% Get the dimensions first
q = size(y, 1); % Dimension of output
l = size(y, 2); % Total length
m = size(u, 1); % Dimension of input
p = l/2-1; % We select half minus -1 else Ybar can be unstable for SISO noise free case

% Create V matrix
V = zeros((q+m)*p + m, l-p);

% Begin with the first m rows for V
for k = 1:m
V(k, 1:l-p) = u(k, p+1:l);
end

% Now do the rest (q+m)*l rows for V. We want to implement v = [u;y] into V - This is equation 8
positionrow = 1;
for row = m:(q+m):(q+m)*p
% For u
for k = 1:m
V(row + k, 1:l-p) = u(k, p-positionrow+1:l-positionrow);
end
% For y
for k = 1:q
V(row + k + m, 1:l-p) = y(k, p-positionrow+1:l-positionrow);
end
positionrow = positionrow + 1;
end

% Important to have part of y
y_part = zeros(q, 1:l-p);
for k = 1:q
y_part(k, 1:l-p) = y(k, p+1:l);
end

% Solve for non-filtred markov parameters
X = y_part*inv(V'*V)*V';


If you know how many signals are there in the columns of $$X$$, you can group the $$X$$ vector into groups of 3 symbols. In a group $$\{X[n],X[n+1],X[n+2]\}$$, the lowest value will be the green value, highest value will be red value and mid value will be blue value. You can start grouping by knowing the value of location of red or green samples. For example, if you start with $$n=3$$ as the red value, even if indexing changes for blue and green, it would not affect the extraction of these signals as green is always lowest in a group and red is always highest in a group.