close all; clear;

% W_N =e^{-j\frac{2\pi }{N}}

N = 8;
W = zeros(N, N);
for a = 0:1:N-1
    for b = 0:1:N-1
        W(a+1,b+1) = exp(-1j*2*pi*a*b/N);
    end
end

m = N/2;
W = exp(-2*pi*sqrt(-1)/N).^(0:m-1)'

N1 = 4; m1 = N1/2;
A = [1 2 3 4; 5 6 7 8; 8 7 6 5; 4 3 2 1]
A(2,1)
A(:,2)
A(1:m1,1:2:N1-1)

C = [1 2 3; 2 3 4; 5 6 7]
B = [3; 7; 1]
C*B

x = (0:15)';
v = bitrevorder(x);
x_bin = dec2bin(x);
v_bin = dec2bin(v);
T = table(x,x_bin,v,v_bin)

a = mod(4,2)
b = mod(5,2)

N = 5;
if(mod(N,2))
    c = 2
    d = 1
else
    c = 3
    d = 3
end

%


h3 = [1 2];
h4 = [-1 -2];
if (h3 == -h4) & (h4==[-1 -2])
    a = 1
    aass = 1
end

h = [1 2 3 4 5]
N = length(h)
h1 = h(1:1:((N-1)/2))
h2 = h(N:-1:((N+3)/2))
h = reshape(h,1,N)

M = 5
x = [1 1 1 1 1 1 1 1 1 1]
x = [zeros(M,1);x(:)]

x = ones(1, 10)

%

m = 10; M = 100; L = 1; g = 9.81;
KP = 1; KI = 1; KD = 1;
syms x;
eqn = M*L*x^3 - KD*x^2 - ((M+m)*g+KP)*x - KI == 0;
s = solve(eqn, x);
digits(6)
vpa(s) 

%

close all; clear;
x = [1 2 3 4 5 6 7 8];
X = fft(x); N = length(X);
W = zeros(1,N);
for n = 1:1:N
    W(n) = X(1:1:N)*exp(-1*sqrt(-1)*2*pi*(n-1).*(0:1:N-1)'/N);
end
W = W./N

(0:1:N-1)'

%

close all; clear;
m = 10; M = 100; L = 1; g = 9.81;
b = [-1/(M*L)]; % -0.01
a = [1 0 -(M+m)*g/(M*L)]; % [1 0 -10.7910]
figure; zplane(b,a);
[zero,pole,k] = tf2zp(b,a)

b_pid = [1 -0.285 -9.885];
% b_pid = [-1 3.285 0];
a_pid = [1];
b_all = conv(b_pid, b);
a_all = conv(a_pid, a);
figure; zplane(b_all,a_all);

sys = tf(b_all, a_all);
figure; bode(sys); grid on;
figure; nyquist(sys); grid on;

T_sys = feedback(sys,1,+1);
figure; bode(T_sys); grid on;
figure; nyquist(T_sys); grid on;

%

close all; clear;
a = [1 2 3 4; 5 6 7 8];
a(1,2)
length(a)

nm = [1 3 3 1 3 5 13 1] 
dn = [3 0 1 0 7 13 2 2]
[ss,gn] = tf2sos(nm,dn)

x = [1 2 3 4 5 6 7 8]
X = fft(x); N = length(X)
u = zeros(6,1); u(2) = 2;
u

%

