我正在尝试通过Artificial-Neural-Network-Based Phase-Locking Scheme for Active Power Filters等人在论文Mohammad M. K. Qasim 中重新创建作品。
在第2部分:使用NLS进行频率估算,他说:
然后他说:
因为A对于A是不可逆的(即A不是方矩阵) 过度确定的线性方程组,无法求解 (6)直接。这个问题可以很容易地通过解决 A的伪逆
问题:
这是我的代码:
%% 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-我的代码正确吗,我是否按照公式Uf正确计算U?
2-我一直收到错误消息:警告,矩阵接近奇异或缩放错误。结果可能不正确