|
Examples of MatBasic calculation system application
MatBasic environment can be used for calculations of a wide range of complexity – from school-level sums to
sophisticated science problems solution. This part contains several examples of the environment application.
- Example: School-level sum "Snowflake"
- Program module of checking an algorithmic metering entry to a set polygonal area
- Program module of a frequency determination sensor
- Simulation model of a synchronous generator
Nonsynchronous regimes in power engineering systems are characterized by a change of E.M.F. vector of any stations
for more then 360 degrees and equal systems’ frequencies disagreement, i.e. their difference from normal values of fnom.
These features of a nonsynchronous regime can be used for it’s recognition. A more universal solution is determination of a network system frequency
at the protection area because the information about neighboring equal systems E.M.F. vectors’ angles is not always available for a relay
protection subset.
The simplest according to the level of its hardware realization complexity level is the method of network system frequency
metering lying in verification of sampling intervals where a controlling quantity (Vk) changes its symbol:

For the network system frequency calculation it’s necessary to have at least four samples of a controlling quantity at the
borders of symbol change intervals (conditionally "-" to "+"). In a common case a time interval embracing the p number of symbol change periods is calculated. Let’s suppose the count starts from 0:

and ends with:

Within the sampling interval which a value passing through the 0 belongs to a linear rule of its change is observed.
Then the estimate value of p periods’ duration will be a number:

So the system frequency estimate is:

Let’s write a frequency determination function using MatBasic language basing upon the algorithm:
% Data – source signal sampling array
% Pnum – number of periods used for frequency calculation
% TimeLength – signal duration
% Tau – sampling period
function [out] Frequency(Data,Pnum,TimeLength,Tau)
global max_fr;
out=max_fr;
NumIter=TimeLength/Tau;
i = 1;
while( Data[i]*Data[i+1] >= 0)
i++;
if (i== (NumIter - 1))
break;
end
end
Ko = i;
m = 1;
n = 1;
for (i = Ko+1:NumIter)
if ( Data[i]*Data[i+1] < 0)
if (n == (2*Pnum))
Kp = i;
pT = Tau*(Kp - Ko + Data[Ko+1]/( Data[Ko+1]-Data[Ko] ) –
Data[Kp+1]/(Data[Kp+1]-Data[Kp] ) );
out[m++] = Pnum / pT;
Ko = Kp;
n = 1;
else
n++;
end
end
end
end |
In order to check our function working capacity let’s make up code outputting results in graphical form:
% global variable; this value will be returned in case frequency determination is
% frequency determination is impossible
global max_fr;
max_fr=1e20;
tau = 0.001; % sampling period
period_num = 1; % number of periods for frequency determination
time_length = 0.3; % signal duration
k=1;
for (i=0:time_length:tau)
Data[k++] = F(i); %F – source signal function
end;
ft=fvec(0,time_length,tau);
freq = Frequency(Data,period_num,time_length,tau);
fd=fvec(1,max(size(freq)),1);
posplot 1,1;
plot2d #Frequency (ft,Data,title="Source signal");
posplot 1,2;
plot2d #Frequency (fd,freq,title="Signal frequency"); |
In order to do sensor analysis let’s set different formulas of function F.
Ideal sinusoid with 50Hz frequency
function F=F1(t)
F = 100 * sin ( (2*PI*50)*t + 30*PI/180);
end |

In that case frequency is determined in an almost ideal way. But there exist no ideal
signals in real life so in order to estimate our frequency sensor we run through it a signal bearing some noise.
Noisy 50Hz sinusoid
function F=F2(t)
F = 100 * sin ( (2*PI*50)*t + 30*PI/180) + 100*0.05*rnd(1);
end |
In this case accuracy decreases significantly and amounts to 0.2 Hz during a frequency
calculation at one period which is inappropriate. Let’s calculate frequency during five periods in order to increase accuracy.
As it’s seen at the pic.2 the accuracy in that case varies between 0.02 – 0.03 Hz.

Mixed signal
function F=F3(t)
F = 110 * sin ( (2*PI*52)*t ) + 80 * sin( (2*PI*47)*t + 30*PI/180);
end |
As it’s seen from the function the raw signal consists of two periodical components of
different frequencies. Let’s calculate this signal frequency during 10 periods. As it’s seen from the graph the signal frequency is
close to the frequency 110 * sin ( (2*PI*52)*t ) .
<< To the top
|