Equivalent of MATLAB's unwrap

Is there a Julia function that is equivalent to MATLAB’s unwrap? It is the function that shift angles by multiples of to make them look distributed continuously.

https://docs.juliadsp.org/stable/util/, can also do more than 1 dimension.

1 Like

You can also use FFTViews which will use periodic boundary conditions when indexing.

If you don’t want to use an external package, you can easily define an equivalent function in Julia:

function unwrap!(x, period = 2π)
	y = convert(eltype(x), period)
	v = first(x)
	@inbounds for k = eachindex(x)
		x[k] = v = v + rem(x[k] - v,  y, RoundNearest)

And then use array views if you want to operate along a specific dimension.

FFTViews sounds great, but not sure how to use it to unwrap angles. Could you show me an example?

That v[-4:3] in the README performs unwrapping.

I don’t think FFTViews is doing unwrapping that I want. In my problem the periodic boundary condition is applied to the values, not the indices. @jagot’s solution works for me.

1 Like