Trouble Unwrapping Phase Data

9 次查看(过去 30 天)
Spencer Ferris
Spencer Ferris 2023-12-9
回答: Akshat Dalal 2023-12-18
I am having some trouble iterating through some circular voltage data that ranges from 4.5 to .5. As the data approaches the max and min, there will be a sudden transition from a low value near the minimum (i.e. .500001) to a high value near the max (i.e. 4.49999), and vice versa if going in the other direction. In other words, the data is circular and could be represented with degrees or radians. I have confirmed that the data never goes above or reaches 4.5 and never goes below or reaches .5.
I'm trying to manually unwrap the data (I've tried a few functions, such as unwrap(), with no success, but if you have suggestions I am open to trying them out) but am having issues where I am still seeing jumps in the unwrapped/accumulated values that I end up with after my iteration through the structure they are contained within. The code I wrote seems to mostly work but when there are transitions from the max (~4.5) to the min (~.5) there are still jumps in the value I get as output. Here's the code I've tried.
% Intialize the size of the array first.
BinaryDataStructure.Channel0BinaryDataUnwrappedVoltage = zeros(size(BinaryDataStructure.Channel0BinaryDataNewTimeBase));
Ch0NumberOfCycles = 0;
JumpsValue = 2.0;
% Manual unwrapping of VOLTAGE data.
for i = 1:length(BinaryDataStructure.Channel0BinaryDataNewTimeBase)
if i == 1
BinaryDataStructure.Channel0BinaryDataUnwrappedVoltage(i) = BinaryDataStructure.Channel0BinaryDataNewTimeBase(i);
BinaryDataStructure.Channel1BinaryDataUnwrappedVoltage(i) = BinaryDataStructure.Channel1BinaryDataNewTimeBase(i);
end
if i > 1
% Channel 0 - Voltage INCREASES when going in the right direction.
% If it is a non-jump voltage transition.
if abs(BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) - BinaryDataStructure.Channel0BinaryDataNewTimeBase(i-1)) < JumpsValue
BinaryDataStructure.Channel0BinaryDataUnwrappedVoltage(i) = abs(BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) + (4*(Ch0NumberOfCycles)));
else
if BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) - BinaryDataStructure.Channel0BinaryDataNewTimeBase(i-1) < 0
Ch0NumberOfCycles = Ch0NumberOfCycles + 1;
BinaryDataStructure.Channel0BinaryDataUnwrappedVoltage(i) = BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) + (4*Ch0NumberOfCycles); %ADJUST USING THIS ONE!!!
end
if BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) - BinaryDataStructure.Channel0BinaryDataNewTimeBase(i-1) > 0
Ch0NumberOfCycles = Ch0NumberOfCycles - 1;
BinaryDataStructure.Channel0BinaryDataUnwrappedVoltage(i) = BinaryDataStructure.Channel0BinaryDataNewTimeBase(i) + (4*Ch0NumberOfCycles); %ADJUST USING THIS ONE!!!
end
end
end
end
Based on the direction the change in voltage goes in during the transition points (which are captured by the Jumps value, the data is sampled at 3840hz and there is no way there would be a jump that big other than during the transition points) the number of total cycles is either increased or decreased. And then I use this to update the value of the Unwrapped voltage, but I still get jumps during these transition points.
  1 个评论
Mathieu NOE
Mathieu NOE 2023-12-11
hi
it would be nice to have data + maybe a picture that would help understand the issue

请先登录,再进行评论。

回答(1 个)

Akshat Dalal
Akshat Dalal 2023-12-18
Hi Spencer,
I understand that you are getting circular data which could be represented as either degrees or radians, and you want to unwrap it to a linear scale.
I went through your code for manual unwrapping and I believe your changes to 'Ch0NumberOfCycles' are getting cascaded in the code. For example,
  1. Lets say your current iteration in the data is increasing, i.e Channel0BinaryDataNewTimeBase(i) - Channel0BinaryDataNewTimeBase(i-1) > 0.
  2. Now at the jump point, the data would jump from 4.5 to 0.5, i.e Channel0BinaryDataNewTimeBase(i) - Channel0BinaryDataNewTimeBase(i-1) < 0 and it would hit the first if condition, and 'Ch0NumberOfCycles' would be incremented along with Channel0BinaryDataNewTimeBase(i), making it greater than 4.
  3. Now consider Channel0BinaryDataNewTimeBase(i+1), since your data is circular and there was a jump point at Channel0BinaryDataNewTimeBase(i), Channel0BinaryDataNewTimeBase(i+1) will also be around the old value of Channel0BinaryDataNewTimeBase(i), i.e, 0.5.
  4. Thus, this will again create a jump point and you will again go into the else part of your if condition, incrementing 'Ch0NumberOfCycles' again, causing a cascading effect.
If you would like to manually unwrap your data, I suggest you to modify your code in the following way:
  1. Once you encouter a jump point, cache your changes to Channel0BinaryDataNewTimeBase until the next jump point.
  2. At the next jump point, apply your cached changes to the original data and follow the same steps till end of data.
This would remove the unnecessary cascading to 'Ch0NumberOfCycles'.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by