Hey @ana, you can achieve the above requirement by implementing a loop that processes your input matrix in chunks of 40 samples. At each iteration, you will:
- Transfer the next 40 samples from the input matrix to a buffer.
- Extract the last 26 samples from this buffer and move them to the stack.
Here is the sample code , Please take it as a referecne and modify it accordingly.
% Initialize your input matrix and stack
input_matrix = rand(168, 1); % Replace with your actual data
stack = zeros(26, 1);
% Define the size of each chunk and the number of samples to send to the stack
chunk_size = 40;
stack_size = 26;
% Calculate the number of iterations needed
num_iterations = floor(length(input_matrix) / chunk_size);
% Process each chunk
for i = 1:num_iterations
% Calculate the start and end indices for the current chunk
start_idx = (i-1) * chunk_size + 1;
end_idx = start_idx + chunk_size - 1;
% Transfer 40 samples to the buffer
buffer = input_matrix(start_idx:end_idx);
% Extract the last 26 samples from the buffer to the stack
stack = buffer(end-stack_size+1:end);
% Do something with the stack if needed
% For example, display it or process it further
fprintf('Iteration %d - Stack samples:\n', i);
disp(stack);
end
% Handle any remaining samples if the input matrix size is not a multiple of 40
remaining_samples = mod(length(input_matrix), chunk_size);
if remaining_samples > 0
buffer = input_matrix(end-remaining_samples+1:end);
if length(buffer) >= stack_size
stack = buffer(end-stack_size+1:end);
fprintf('Final Stack samples:\n');
disp(stack);
end
end