Interpolated phase data will not unwrap

2 views (last 30 days)
I would like to unwrap some phase data after it is interpolated, but it's not working.
The results of this plot should look similar, but they don't.
freqHz = [20.51 21.97 23.44 24.9 26.37 27.83 29.3 30.76 32.23 33.69 35.16 36.62 38.09 39.55 41.02 42.48 43.95 45.41 46.88 48.34 49.8 51.27 52.73 54.2 55.66 57.13 58.59 60.06 61.52 62.99];
phaseDeg = [142.97 120.69 90.32 67.07 50.38 28.25 5.72 -15.26 -29.47 -49.75 -68.85 -93.73 -119.85 -136.02 -145.41 -161.94 -179.65 174 155.32 132.26 112.73 94.44 78.02 64.64 58.87 62.91 66.56 51.86 41.99 36.01];
freqHzTarget = [20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50];
phaseDegInterpolated = interp1(phaseDeg, freqHz, freqHzTarget);
phaseDegUnwrapped = unwrap(deg2rad(phaseDeg));
phaseDegInterpolatedUnwrapped = unwrap(deg2rad(phaseDegInterpolated));
semilogx(freqHz, phaseDegUnwrapped, freqHzTarget, phaseDegInterpolatedUnwrapped)

Accepted Answer

Star Strider
Star Strider on 10 Feb 2022
The arguments to the interp1 call are incorrect. The first two should be reversed, since the interpolation is over frequency.
Try this —
freqHz = [20.51 21.97 23.44 24.9 26.37 27.83 29.3 30.76 32.23 33.69 35.16 36.62 38.09 39.55 41.02 42.48 43.95 45.41 46.88 48.34 49.8 51.27 52.73 54.2 55.66 57.13 58.59 60.06 61.52 62.99];
phaseDeg = [142.97 120.69 90.32 67.07 50.38 28.25 5.72 -15.26 -29.47 -49.75 -68.85 -93.73 -119.85 -136.02 -145.41 -161.94 -179.65 174 155.32 132.26 112.73 94.44 78.02 64.64 58.87 62.91 66.56 51.86 41.99 36.01];
freqHzTarget = [20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50];
% phaseDegInterpolated = interp1(phaseDeg, freqHz, freqHzTarget); % Original
phaseDegInterpolated = interp1(freqHz, phaseDeg, freqHzTarget); % Corrected
phaseDegUnwrapped = unwrap(deg2rad(phaseDeg));
phaseDegInterpolatedUnwrapped = unwrap(deg2rad(phaseDegInterpolated));
figure
semilogx(freqHz, phaseDegUnwrapped, freqHzTarget, phaseDegInterpolatedUnwrapped)
This appears to be the desired result!
.
  3 Comments
Star Strider
Star Strider on 10 Feb 2022
As always, my pleasure!
Thank you!
‘Maybe it is actually better to unwrap before interpolation.
I agree. That would remove the ‘spike’ discontinuity, since nothing like it is present in the original vector.
..

Sign in to comment.

More Answers (0)

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by