- refactored

This commit is contained in:
2022-06-30 13:32:40 +02:00
parent 77cd5261b1
commit 776932e5d1
144 changed files with 0 additions and 38 deletions
+53
View File
@@ -0,0 +1,53 @@
## Copyright (C) 2017 Jens Ahrensfeld
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {@var{retval} =} hmm_eval (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn
## Author: Jens Ahrensfeld <ahrensfeld@w2ess001vm>
## Created: 2017-06-14
function sv = hmm_eval (A, numIter)
numStates = length(A)
C = zeros(1,numStates);
#A = rand(numStates, numStates)
for s=1:numStates,
A(s,:) = A(s,:) ./ sum(A(s,:));
[AS(s,:), Ai(s,:)] = sort(A(s,:));
AC(s,:) = cumsum(AS(s,:));
end
A
AC
s=1;
for n=1:numIter,
sv(n) = s;
stateProbs = AC(s,:);
z = rand();
c = find (z <= stateProbs);
s = Ai(s, c(1));
C(s) = C(s) + 1;
end
plot(1:numIter, sv, 'ro-'); grid;
C=C/numIter
endfunction
+23
View File
@@ -0,0 +1,23 @@
function [y, zf] = movingavg(x, zi)
if ~isstruct(zi)
N = zi;
zf = struct('N', N, 's', zeros(N+1, 1), 'ri', 2, 'wi', 1, 'y', 0);
else
zf = zi;
end
xn = x/zf.N;
zf.y = zf.y + xn - zf.s(zf.ri);
y = zf.y;
zf.ri = zf.ri + 1;
if zf.ri > length(zf.s)
zf.ri = 1;
end
zf.s(zf.wi) = xn;
zf.wi = zf.wi + 1;
if zf.wi > length(zf.s)
zf.wi = 1;
end
+13
View File
@@ -0,0 +1,13 @@
% Power estimation on discrete signals
function y = rms(x,Nw)
N = length(x);
y = zeros(1,N);
y(1) = x(1)^2;
for k = 2:N-Nw,
for n = k:Nw+k,
y(n) = y(n-1)*(1-1/Nw) + 1/Nw*x(n)^2;
end;
end;
+21
View File
@@ -0,0 +1,21 @@
% Power estimation on discrete signals
function [y,yf] = rms(x,Nw,yi)
N = length(x);
y = zeros(1,N);
Nb = ceil(N/Nw);
xp = zeros(1,Nb*Nw);
yp = zeros(1,Nb*Nw);
xp(1:N) = x(1:N);
yp(1) = abs(x(1));
for k = 1:Nb-1,
for n = (k-1)*Nw+2:k*Nw+2,
yp(n) = yp(n-1)*(1-1/Nw) + 1/Nw*abs(x(n));
end;
end;
y = yp(1:N);
+9
View File
@@ -0,0 +1,9 @@
% Power estimation on discrete signals
function [y,yf] = sm2(x,yi,arf)
N = length(x);
x(1) = x(1) + yi*(1/arf-1);
x = abs(x);
a = [1,-(1-arf)];
y = filter(arf,a,x);
yf = y(N);
+21
View File
@@ -0,0 +1,21 @@
% Power estimation on discrete signals
function [y,yf] = smhs(x,Nw1,Nw2,yi)
N = length(x);
y = zeros(1,N);
x = abs(x);
if (x(1) > yi)
y(1) = (1-1/Nw1)*yi + (1/Nw1)*x(1);
else
y(1) = (1-1/Nw2)*yi + (1/Nw2)*x(1);
end;
for n = 2:N,
if (x(n) > y(n-1))
y(n) = (1-1/Nw1)*y(n-1) + (1/Nw1)*x(n);
else
y(n) = (1-1/Nw2)*y(n-1) + (1/Nw2)*x(n);
end;
end;
yf = y(N);