Why is the 'rfinterp1' function creating a jagged line between data points?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 16 Feb 2021
Commented: Walter Roberson
on 23 Mar 2024
I have an S-parameter object for which I am plotting the parameter values. I want to draw a line connecting the data points using linear interpolation. However, when I use the function 'rfinterp1', I see a jagged line instead of a linear one as shown below. Why is this happening?

Example script:
>> y = rfparam(sobj_raw_s4p, 2, 1);
>> x = sobj_raw_s4p.Frequencies;
>> xnew = f_s4p;
>> ynew = interp1(x, y, xnew);
>> figure; hold on; plot(x, db(abs(y)), 'o'); plot(xnew, db(abs(ynew)), '-'); hold off
Accepted Answer
MathWorks Support Team
on 16 Feb 2021
The 'rfinterp1' function is behaving as expected. The difference in the data and the interpolation is due to the fact that the data is complex. When interpolating complex numbers, 'interp1', the function behind 'rfinterp1', interpolates the real and imaginary parts separately.
There are two ways to resolve this, depending on your desired results.
Option 1:
The 'rfinterp1' function should interpolate the abs( ) of the 'sobj_raw_s4p' data. You can do this by putting the following command after the definition for 'sobj_raw_s4p'. For the data to line up with the interpolation, this command should be used after the definition of 'sobj_raw_s4p' for the raw data as well.
>> sobj_raw_s4p.Parameters = abs(sobj_raw_s4p.Parameters);
Option 2:
You can plot the real and/or imaginary parts separately. This would look like replacing the 'abs( )' command with the 'real( )' or 'imag( )' commands in all the 'plot' functions.
1 Comment
Walter Roberson
on 23 Mar 2024
Ritesh Bhat comments
I think Option 1 modifies the original s-parameters themselves and must be used carefully. For instance, if we want to cascade two s-parameters using cascadesparams function after interpolation, this may give the wrong result.
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!