当我离开我的电脑时,我没有回答这个问题,因此今天早上我自嘲了。
下面是一些将 David K 的答案付诸实践的代码。使用提供的随机种子来保证一个体面的例子。注释该行以每次查看不同的示例。
%Seed maintenance
% This seed seems to demonstrate the desired behavior. Comment this out
% to see multiple examples
rng(523205203)
%Parameters
N = 500;
commonRate = 10;
independentRate = 2;
nSeries = 4;
%Some random data
common = randn(N*2,1)*commonRate;
independent = randn(N*2,nSeries)*independentRate;
%Build up some interesting data series
data = cumsum(bsxfun(@plus,common, independent), 1);
data = data((N+1):end, :);
%Setup observed data, observing modulated data
observedData = mod(data, 360)-180;
%Utility functions
% Basic unwrapping, in deg
unwrap_deg = @(x) unwrap(x/180*pi)*180/pi;
% Unwrapping, using an arbitrary offset, in deg
unwrapToValue_deg = @(x, value) unwrap_deg(x-value)+value;
% Basic unwrapping, in dim 1, after adjusting columns based on row 1
equalizeAndUnwrap_deg = @(x) unwrap_deg(...
bsxfun(@plus, ...
unwrapToValue_deg(x(1,:),x(1,1)) - x(1,:), ... %Per column, add the difference ebtween row 1 and the unwrapped row 1
observedData)...
);
%Use functions to correct observred data
unwrappedObservedData = unwrap_deg(observedData);
equalizedUnwrappedObservedData = equalizeAndUnwrap_deg(observedData);
%Plot
figure(2932323)
subplot(311)
plot(observedData,'.')
subplot(312)
plot(unwrappedObservedData,'.')
subplot(313)
plot(equalizedUnwrappedObservedData,'.')