Skip to content

Instantly share code, notes, and snippets.

@joastbg
Created June 2, 2016 13:39
Show Gist options
  • Save joastbg/336ecd96a5cbe8cba4a67254cf673c87 to your computer and use it in GitHub Desktop.
Save joastbg/336ecd96a5cbe8cba4a67254cf673c87 to your computer and use it in GitHub Desktop.
Fibonacci sequence in state-space form - Octave (MATLAB)
%% Fibonacci sequence in state-space form
% Define the state-space system parameters:
A = [0 1; 1 1]; % State transition matrix
B = [0; 1]; C = [1 1]; D = 1; % Input, output, feed-around
% Set up the input signal, initial conditions, etc.
x0 = [0;0]; % Initial state (N=2)
Ns = 13; % Number of sample times to simulate
u = [1, zeros(1,Ns-1)]; % Input signal (an impulse at time 0)
y = zeros(Ns,1); % Preallocate output signal for n=0:Ns-1
% Perform the system simulation:
x = x0; % Set initial state
for n=1:Ns-1 % Iterate through time
y(n) = C*x + D*u(n); % Output for time n-1
x = A*x + B*u(n); % State transitions to time n
end
y' % print the output y (transposed)
@WizxGamer
Copy link

Aamazing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment