Interpolation 1-D
1 view (last 30 days)
Show older comments
Hi, I have a set of measured data s21_ef_d (i have included the mat file) Then I want to interpolate the 3dB cut off value but it seems like Matlab gave me the wrong anwser. Here is my code:
load('s21_ef_d.mat');
f=linspace(500e6,3e9,1601);
[a0_ef_d b0_ef_d]=max(20*log(abs(s21_ef_d)));
f01=interp1(20*log(abs(s21_ef_d)),f/1e9,(a0_ef_d-3),'spline');
Then Mtalab gave me f01=1.7521e+09 which should be only around 1.73e+09. Could anyone please help? Thanks
0 Comments
Accepted Answer
John D'Errico
on 29 Jun 2017
Edited: John D'Errico
on 29 Jun 2017
NEVER just throw anything (without thought) into a numerical routine and expect intelligence to come out of it. What is the old saying, garbage in, garbage out?
plot(20*log(abs(s21_ef_d)),f/1e9,'.')
This is what you are trying to use interp1 on.
Does that curve represent a single valued function of the independent variable? The independent variable here is 20*log(abs(s21_ef_d)). NO! It is not single valued.
Interpolation will result in random junk.
Apparently you want to locate the points where the curve passes through (a0_ef_d-3). Since we have
a0_ef_d-3
ans =
-93.97
It looks like there will be two solutions.
The simplest way to compute those two locations is to use my slmsolve utility, applied to a spline formed from the data passed in in reverse order. slmsolve is part of my SLM toolbox. As it turns out, I wrote that tool to also work on the pp form splines as returned from spline or pchip.
spl = spline(f/1e9,20*log(abs(s21_ef_d)))
spl =
struct with fields:
form: 'pp'
breaks: [1×1601 double]
coefs: [1600×4 double]
pieces: 1600
order: 4
dim: 1
result = slmsolve(spl,a0_ef_d-3)
result =
1.6056 1.7314
plot(20*log(abs(s21_ef_d)),f/1e9,'b-')
hold on
plot(a0_ef_d-3,result','rs')
You can get the SLM tools here:
https://www.mathworks.com/matlabcentral/fileexchange/24443-slm-shape-language-modeling
3 Comments
John D'Errico
on 29 Jun 2017
No. PCHIP, applied to a non-single valued function as you have, will NOT give you a correct answer. It will just not give you quite as bad an answer. PCHIP also requires a single valued function.
I think both of those tools just sort your points on x, only then build a spline. But if you sort the data on x, it removes the essential nature of the curve.
So you need here to switch the axes, because really, the curve is single valued when viewed as x(y), thus x as a function of y. Even there, there will be two solutions to the inverse function.
More Answers (0)
See Also
Categories
Find more on Smoothing 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!