How to fit a base(excluding the peak) of a curve and subtract the fitted base with its corresponding unfitted curve

Hi all,
I am trying to fit a base of a curve(excluding peak form data point 10:22) using a polynomial expression, I want to programmatically fit the base line (excluding peak) and do the subtraction of the fitted and unfitted data.
Is there a way to fit just the base and exclude the peak data points(from 10:22)?
single datasets is attached.

3 件のコメント

Why not make it easy for us to give advice and attach a screenshot of the plotted data?
Ankit Gupta
Ankit Gupta 2015 年 9 月 29 日
編集済み: Ankit Gupta 2015 年 9 月 29 日
This is the raw single dataset, I just wanna fit the baseline excluding the peak data point form 10:22 Mat file contains "Tabs" as ydata and freq as xdata
dpb
dpb 2015 年 9 月 29 日
Despite the structure in the "baseline" outside the peak, without further information on the system you can't realistically fit much more than a linear baseline value in the region of the peak itself. When you use the polynomial of high order, there's not telling what it'll do in that region.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2015 年 9 月 28 日
Or you can certainly extract everything except elements 10 to 22 and pass them into interp1(), polyfit(), or fitlm() and get a polynomial everywhere, even over the missing data points.
dpb
dpb 2015 年 9 月 28 日
But despite not having the data set for viewing/testing, sure...
ix=[1:9 23:length(x)]; % include points
b=polyfit(x(ix),y(ix),2); % fit second order baseline
ysub=y-polyval(b,x); % subtract baseline over entire range

5 件のコメント

hi dpb, I want to use the 8th degree polynomial fit: fittype('p1*x^8 + p2*x^7 + p3*x^6 + p4*x^5 + p5*x^4 + p6*x^3 + p7*x^2 + p8*x + p9');
and my dataset is 2101x32, so single data set will be 1x32.
So I tried something like this, but the polynomial fitting(8th degree) doesn't work and which causes i guess subtraction to not work.
data is the y data which 2101x32 dpuble, freq is x data which 1x32 double
function [offsets,subt_data]=BaseFit_1(data,freq)
data2=transpose(data);
freq2=transpose(freq);
exc=excludedata(freq2(:,:),data2(:,:),'indices',10:22);
polybase=fittype('p1*x^8 + p2*x^7 + p3*x^6 + p4*x^5 + p5*x^4 + p6*x^3 + p7*x^2 + p8*x + p9');
fo=fitoptions(polybase);
fo.Exclude=exc;
for i=1:5; // trying on just first 5 data sets
polybase=fit(freq2(:,:),data2(:,i),polybase,fo);
polyfits(:,i)=feval(polybase,freq2);
figure(1);
plot(freq,data(i,:),freq,polyfits(:,i));
offsets(i,:) = polybase(5);
subt_data(:,i) = (polyfits(:,i) - data2(:,i));
figure(2);
plot(freq,data(i,:),freq,subt_data(:,i));
end
dpb
dpb 2015 年 9 月 28 日
"I want to use the 8th degree polynomial fit" This is undoubtedly a very bad idea...it'll surely have many undesirable inflections. Would have to see the data to see just how badly it performs but I'm not surprised results aren't as expected.
Specifics will need the data; as IA says as a minimum if can't figure out the attachement for a file attach a sample plot.
Hi dpb, datasets are attached , its 2101x32 double(ydata) and freq is 1x32 double (xdata)
Ankit Gupta
Ankit Gupta 2015 年 9 月 29 日
編集済み: Ankit Gupta 2015 年 9 月 29 日
mat file Hi Attached the mat file, in the Mat file "Tabs" is the y data and Freq is the x data

サインインしてコメントする。

質問済み:

2015 年 9 月 28 日

コメント済み:

dpb
2015 年 9 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by