ADALINE Algorithm Vs FFT for A/D and signal processing

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

ADALINE Algorithm Vs FFT for A/D and signal processing

#1 Post by mbluethunder7000 » 18 Jan 2009 01:21

Hello my friends

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

mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

#2 Post by mbluethunder7000 » 21 Jan 2009 06:11

Any Advice?

Is there any good reference to learn the programming in c or pascal the neural network algorithms for microcontroller and dsps?

mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

#3 Post by mbluethunder7000 » 02 Feb 2009 22:11

While there is no any reply from members or mikroelektronika team. I think that such kind of algorithm is unknown in this forum and no one tried to use it before.

I would like to ask for another something else which is the method to divide matrices using the Pascal library.

Hope to find some help
Thanks in advance

BR

goran.marinkovic
mikroElektronika team
Posts: 265
Joined: 25 Nov 2008 09:09

#4 Post by goran.marinkovic » 03 Feb 2009 11:35

Hi,

I am really sorry for your waiting.
Your question is sufficiently complicate.
Wee need some time to consider the mentioned problem.
I will inform you, when I get some results.

I hope that you understand.

Regards

mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

#5 Post by mbluethunder7000 » 03 Feb 2009 23:15

goran.marinkovic wrote:Hi,

I am really sorry for your waiting.
Your question is sufficiently complicate.
Wee need some time to consider the mentioned problem.
I will inform you, when I get some results.

I hope that you understand.

Regards
Hello goran

I am completely understand the situation as I said before that such kind of algorithm is new here in this forum.

I just want to know the method to divide the matrices using the Pascal library

Thanks a lot for your reply
BR

mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

#6 Post by mbluethunder7000 » 18 Feb 2009 21:31

I am trying to build a code for the above matlab code using the matrix functions which are part of DSP library in micropascal. I noticed that I have to use word in all my calculations but I am working with a real numbers. (Float numbers )

For example: Regarding this function [Matrix_Scale] I need to multiply (0.1) in a matrix and I don't know how can I do that

Also I have a matrix with elements generated from sin & cos functions

Plus I don't know how I can make the matrix inverse

I hope to find some help regarding this functions

Best Regards

SamY Fareast
Posts: 46
Joined: 05 Aug 2007 07:15
Location: Shizuoka JAPAN

#7 Post by SamY Fareast » 22 Feb 2009 16:14

Hi.
DSPIC use radix 1.15 style for denote real number (while MP use IEEE style float point).

So if you fill matrix with ADC result and ADCON1<9:8>(form,1:0.) is 11 or 10, scale value will be $0CCD(%0000 1100 1100 1101).
This means,
0.1(decimal) = 2^(-4) + 2^(-5) + 2(-8) + 2^(-9) + ....
You can calculate this value by mikro Pascal s converter window.( or simply multiply 32768(decimal)=%1000 0000 0000 0000)

Good luck!

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”