假设此时我们拥有一组数据:Data = [-59, -92, -126, -158, 166, 133, 96, 61, 26, -7, -18, -59, -92, -126, -158, 166, 133, 96, 61, 26, -7, -18];
如上图所示,这些数据呈现一种类似周期性的循环,但这并不是真的周期函数,只是因为当他的数值跨越 ±π 时,就会根据其变化形式,条编导边界重新计算
这种状态我们一般称之为相位的卷绕或相位的折叠,用wrap表示,则相位饿解卷绕被称为unwrap
%% unwrap
% unwrap(x) = wrap(x) - wrapCycle*wrapNum(x)
% data0
Data = [-59, -92, -126, -158, 166, 133, 96, 61, 26, -7, -18, -59, -92, -126, -158, 166, 133, 96, 61, 26, -7, -18];
subplot(3, 1, 1);
plot(1:length(Data), Data);
title('Ram simulated data')
grid on;
% use system function unwrap
unwrap_Data = unwrap(deg2rad(Data), [], 2);
unwrap_finallyData = rad2deg(unwrap_Data);
subplot(3, 1, 2);
plot(1:length(Data), unwrap_finallyData);
title('Use system function unwrap')
grid on;
% try to simulate unwrap
length_Data = length(Data);
finallyData = [];
CycleNumber = [];
wrapCycle = [];
% calculata CycleNum
for i = 1 : length_Data
if i > 1
if (Data(i) - Data(i-1)) > 180
CycleNumber(i)= CycleNumber(i-1) + 1;
elseif (Data(i) - Data(i-1)) < -180
CycleNumber(i) = CycleNumber(i-1) + 1;
else
CycleNumber(i) = CycleNumber(i-1);
end
else
CycleNumber(i) = 0;
end
end
% calculata wrapCycle
for i = 1 : length_Data
if i > 1
if (Data(i) - Data(i-1)) > 180
wrapCycle(i)= 360;
elseif (Data(i) - Data(i-1)) < -180
wrapCycle(i) = -360;
else
wrapCycle(i) = wrapCycle(i-1);
end
else
wrapCycle(i) = 0;
end
end
% updata Data
for i = 1 : length_Data
finallyData(i) = Data(i) - wrapCycle(i)*CycleNumber(i);
end
subplot(3, 1, 3);
plot(1:length(Data), finallyData);
title('try to simulate unwrap')
grid on;