这将设置为偏移,使第一行的起点为零,并缩放所有数据,使最小值到最大值的范围为255个单位。
我去掉了注释,但包含了一些行,这些行可以替代缩放数据,使其从0&开始;峰值在255。但是,由于存在一些负值,因此总范围为>255
clf;
%call importdata() after changing current directory
B = importdata('sigpros.txt');
%NOTE: I am only plotting the first 59 lines as the rest don't look as good
Bd = detrend(B(:,1:59),0); %remove the zero offset
d = 1000; %vertical spacing
Bs = Bd; %copy of the original data
%Get the initial zero offset from the first line
initOffset = Bs(1,1);
%% xxx Alternatively take the mean across all starting points xxx
% initOffset = mean(Bs(1,:));
for i = 1 : size(Bs,2)
%loop adding constant to each column
Bs(:,i) = Bs(:,i) - initOffset + (i-1) * d ; %subtract the offset from each
end
minV = min(Bs(:));
maxV = max(Bs(:));
%This make the RANGE from min to make = 0-255 units.
Bs_scale = (Bs)*255/(maxV-minV);
%% xxxx If instead you want the peak to be at 255 xxxxx
% Bs_scale = (Bs)*255/(maxV);
%plot the modified matrix
plot(Bs_scale, 'k');
编辑/解释:
Here is what B looks like Raw.
. 它基本上是一系列相互重叠的线条。在你之后
detrend
然而,由于这个信号不是完全对称的,这些线并不完全从零开始。。。它们比以前更接近,但并不完美。
Here is Bd
之后
德特伦德
下一个你的
for
循环最初将每条线间隔1000,增加了
d
so it looked like this
. 因为这些线不是从零开始的,这就是你想要的,我添加了初始偏移项。这些基本上取第一行的第一个点,然后从每一行中减去。从而迫使它从零开始。