Interpolation 1-D

11 Ansichten (letzte 30 Tage)
Shan  Chu
Shan Chu am 29 Jun. 2017
Kommentiert: John D'Errico am 29 Jun. 2017
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

Akzeptierte Antwort

John D'Errico
John D'Errico am 29 Jun. 2017
Bearbeitet: John D'Errico am 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 Kommentare
Shan  Chu
Shan Chu am 29 Jun. 2017
Hi, First of all, I am sorry but I thought the interpolation function will help to define any point that follows the trend of the curve. I didn't know that the curve needs to be a single-valued function of the independent variables. Secondly, I just found that if I changed the method from spline to pchip, it will get the correct answer. I don't know how it works. If you know it, please enlighten me. Finally, thank you for answering and also introducing me your toolbox. It's very helpful. Thanks to David too. It's a rookie mistake.
John D'Errico
John D'Errico am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by