It has been a long time since I wrote my last post here in this forum. I am still alive and doing very well.
Actually I am trying these days to demonstrate a new algorithm related to the neural network techniques called [ADALINE Algorithm] {Adaptive Linear Element}. This algorithm will replace the regular FFT technique in my project.
So based on this new algorithm, I will sample the analogue signal and process the data into this algorithm to get some results related to the voltage magnitude and voltage angle.
Actually I did this algorithm on the matlab program using simulink and using also the m file. I don't know if matlab program is recognized very well here or not but I would like to post here the code of this algorithm in m file as following:
Code: Select all
[color=green]%clear all,
s=600; % number of steps
a=2;
omega=2*pi*50; % power frequency
dt=1/(50*32); % Time step
omegadt=omega*dt; % supply angular frequency
omefdt=2*pi*10*dt;[/color]
[color=blue]%test signal
%-----------------------------------
for k = 1 : s %3000
z(k)=(a + cos(k*omefdt))*cos(k*omegadt+pi/3);
envl(k)=a + cos(k*omefdt);
angfun(k) = pi/3;
end
%omefdt=2*pi*20*dt;
a=4;
for k = 301 : s
z(k)=(a + cos(k*omefdt))*cos(k*omegadt+pi/3);
angfun(k) = pi/3;
envl(k) =a + cos(k*omefdt);
end[/color]
[color=red]% Initilaization
%-----------------
alpha=[.5];
w = [ 1.5 2.6];% 0 0];
N= 1/(60*dt); % Sampling rate
T= 2*pi/(omega*N);
for i=1:s
k=i; %-1 ;
x =[cos(k*omegadt) -sin(k*omegadt)];% 1 -k*T];
% Step One : Compute adaline output
%-----------------------------------
y=x*w';
% Step Two : Update weights (W-H rule)
%------------------------------------------------------
w = w + alpha*(z(i)-y)*x/(x*x') ;
flic(i) = (w(1)*w(1) + w(2)*w(2))^0.5;
phifun(i) = atan(w(2)/w(1));
er(i)=100*(flic(i)-envl(i))/envl(i);
end
ada=flic;[/color]
% Result plots
%-------------
t=[0:1:(s-1)]*dt;
%Plot of estimated envelope
%--------------------------
figure(1)
subplot (411)
plot(t,z)
ylabel ('voltge fliker')
grid
%---------------------------------------------------------
subplot (412)
plot(t,envl,t,flic)
ylabel ('flicker tracking')
grid
%---------------------------------------------------------
subplot (413)
plot(t,er)
ylabel ('% error')
grid
%Plot of estimated phase angle of the fundamental waveform
%---------------------------------------------------------
subplot (414)
plot(t,phifun,t,angfun)
ylabel ('fundamental angle (rad.)'): xlabel('time (s.)')
grid
Be note that the red section is the one which is related to the adaline line algorithm. While
[Z(i)] : Have to be the sample signals from A.D [ The actual signals from A/D in real time ]
[Flic(i)] : have to be the voltage magnitude
[Phifun(i)] : have to be the voltage angle.
[Y ]: have to be the measured wave after processing the input signals with different weights
[x] & [w] are matrices & [W'] is the transport matrix
Green section is the definition part and blue section is not an important because it will be replaced by the sampled signal
-----------------------------------------------------
Now I succeed to sample the voltage signal according to the following points:
1: Sampled voltage value: 500mV shifted to 1.6 V level
2: Analogue port : AN8 – 10-Bit resolution
3: dsPIC Model : dsPIC33F128GP710.
4: Sample frequency : 1.1 MHz ( 900ns)
5: Processsor speed : 40MIPS
So based on the above data, I sampled the input voltage signal and generated a pure sine wave on the matlab program and this sine wave is represented the 220Vac outlet in my home.
According to the above history, I would like to know the following items:
1: How can I convert the above m file to Pascal language to be suitable for dsPIC processing?
2: How can I detect the zero-crossing point to measure the frequency value?
3: How can I stamp a real time to the measurement per one second?
4: how can write a table contains the sampled value in decimal and its time to MMC?
5: referring to the sample frequency, is it suitable for math processing and also for FFT routine?
If there are any more clarification is needed please let me know.
Sorry for the inconvenience and above long discussion
Best Regards
M.Alaa