%% Unwrap Signal
% This example shows how to use the <docid:dsp_ref#f5-1119485 Unwrap> block
% to unwrap a 3-by-2-by-3 array that has discontinuity.

% Copyright 2019 The MathWorks, Inc.

%%
% Each 3-by-2 frame of the signal has a discontinuity. In the first frame, there
% is a discontinuity between the second and the third element greater than 
% the tolerance of $\pi$ set in the block parameters.
% In the second frame, the discontinuity between the second and third element
% is less than $\pi$, and in the third frame, the discontinuity is equal to $\pi$. 
% Since we expect the block to wrap signals with discontinuities greater than the 
% tolerance, unwrapping the signal does not affect the second or third frame.
%%
% Open the Simulink model.
model = "ex_unwrap";
open_system(model);
frame1 = [0 0; 2*(pi)/3 0; -2*(pi)/3 0];
frame2 = [2*pi 0; 8*pi/3 0; 9.5*pi/3 0];
frame3 = [4*pi 0; 13*pi/3 0; 16*pi/3 0];
signal = cat(3,frame1,frame2,frame3)
%%
% The |Tolerance| parameter of the Unwrap block is set to $\pi$. The block
% therefore unwraps discontinuities which are larger than $\pi$.

%%
% Run the model.
output = sim(model);
%%
% See that the output, |output.unwrapped_signal| does not have the first
% discontinuity, but the other two remain.
output.unwrapped_output
