我正在研究MATLAB中的功耗信号。我想做的是测量循环时间,例如空闲时间和工作时间。而且,我提取功耗签名。代码还给了我签名的数量(numberofoccurrences
)。
我使用互相关方法(xcorr
)和findpeaks
函数来自相关信号。代码:
S=S-mean(S);%%%%//Signal that I am working with. It's a 200X1 double
%%%%%%%%
IdleLevel = min(S)*1.4;%this will help find peaks above a minimum threshold
invS=-S;% minimum point becomes max
%%%%%%%%
%//find peaks in the inverse signal. hard coded though!
[pks, locs]=findpeaks(invS,'MinPeakHeight',IdleLevel,'MinPeakDistance',40);
%%%%%%%%
%%%%%%%%//signature extraction
for n = 1:length(locs)-1;
sig{n} = S(locs(n):locs(n+1));
end;
%%%%%
%%%%%%%%//correlation between signal and signature 1
[c,lags] = xcorr(S,sig{1});
%%%%%%%%%
%%%//normalisation
c = (1/max(c)).*c;
%%%%%%%
%%%%%%%
[peaksx, locsx] = findpeaks(c, 'MinPeakHeight',0.8,'MinPeakDistance',40);
%%%%
%%%%
numberofoccurrences = length(locsx)
Signatures = sig;
我正在使用的信号如下所示:
我提取的签名示例如下:
从图2中可以看出,有两个感兴趣的领域。闲置的和工作的。
我需要找到一种计算工作时间和空闲时间的方法。我这样做,我采取的是(我认为)total_time
。
for k=1:numberofoccurrences
total_time(k)=length(sig{k});
end
minpeakdistance
是硬编码的。如果有一种技术不使用预定义的值,那将是完美的。