I am trying to recreate the work in the paper : Artificial-Neural-Network-Based Phase-Locking Scheme for Active Power Filters by Mohammad M. K. Qasim & al.
In Section 2 : FREQUENCY ESTIMATION USING NLS, He state :
Then He say :
since A is not invertible (i.e., A is not a square matrix) for the overdetermined system of linear equations, it is not possible to solve (6) directly. This problem can be easily solved by taking the pseudoinverse of A
Question :
I want to calculate a Matrix U, where the variable is f0 (in A matrix)
:
Here is my code :
%% Creating a distored signal (VS)
fs = 20000; % sampling freq = 20KHz
st = 1/fs;
t = 0:st:((1/50)/2)-st; % half a cycle
f0 = 50; % fundamental freq
N = 5;
vfund = 220*sin(2*pi*f0.*t);
vc3 = 50*cos(2*pi*3*f0.*t); % Cos/k=3/amp=50
vc7 = 30*cos(2*pi*7*f0.*t); % Cos/k=7/amp=30
vs5 = 40*sin(2*pi*5*f0.*t); % Sin/k=5/amp=40
vs9 = 10*sin(2*pi*9*f0.*t); % Sin/k=2/amp=10
vTot = vfund + vc3 + vs5 + vc7 + vs9;
close all;
plot(t, vTot, t, vfund);
%% Trying to calculate U for f0 = 48.5
f0_es = 48.5; % example
A = zeros(length(t), 5); % predeclaring A
% calculating A for the value of f0=48.5
for i=1:5
A(:, 1) = sin(2*pi*f0_es.*t); %Fund
A(:, 2) = cos(2*pi*f0_es*3.*t); %Cos3
A(:, 3) = cos(2*pi*f0_es*7.*t); %Cos7
A(:, 4) = sin(2*pi*f0_es*5.*t); %Sin4
A(:, 5) = sin(2*pi*f0_es*9.*t); %Sin7
end
% Calculating U
At = pinv(A); % Step 1 : pseudo inverse of A
id = (A*At); % Step 2 : A*At
idminus = id^-1; % Step 3 : (A*At)^-1
p2 = At*idminus*A; % Step 4 : (A*(A*AT)^-1*A)
p1 = eye(5)-p2; % Step 5 : (I-(A*(A*AT)^-1*A))
1- Is my code right, am i calculating U correctly as in the equation Uf?
2- i keep receiving an error message : Warning, Matrix is close to singular or badly scaled. Results may be inaccurate