필터 지우기
필터 지우기

Is there a way to Un-clip a sine wave?

조회 수: 5 (최근 30일)
Morpheuskibbe
Morpheuskibbe 2019년 10월 17일
댓글: Morpheuskibbe 2019년 10월 17일
I have a pile of data from a sensor and the sensor is getting maxed out. However, I knwo the data SHOULD be a sine wave and the top/bottom is only getting clipped off due to the sensor's limits. Is there a way to write an Mcode that will restore or unclip the sine wave?
I attached the worst of the data. As you can see in the third column, before you even bother to graph it, it's slamming into the top and bottom of the scale repeatedly.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 10월 17일
You can do something like this:
sfcn = @(t,pars) pars(1)+pars(2)*sin(pars(3)*t+pars(end)); % sine-like function with offset and phase-shift
fitfcn = @(pars,y,t,sfcn) sum(( sfcn(t,pars) - y).^2); % Sum-of-square function
Clipped3 = clipped(:,3); % Your thirs column
t = 1:numel(Clipped3); % Some time-array for uniformly sampled data
% Identify your clipped data points:
iBad = find(Clipped3>290|Clipped3<2);
Clipped3(iBad) = []; % Cut those points out
t(iBad) = []; % from data and time-array
pars0 = [150,500,2*pi/(46.7),pi/2];
% this fitting is painfully sensitive to bad start-guess so the above line
% we set the average at 150, the oscillating amplitude to 500, and the angular
% frequency to fit with a period-time of 46-47 time-steps, and the phase-shift
% to pi/2 since your data starts at a peak not a zero
% Fit by minimizing sum of squared residuals:
parsOK = fminsearch(@(pars) fitfcn(pars,Clipped3,t',sfcn),pars0)
%parsOK =
% 166.1 240.25 0.13416 1.7285
plot(clipped(:,3),'b-') % initial curve
hold on
plot(t,Clipped3,'b.') % unclipped points
% Residuals:
plot(t,Clipped3'-sfcn(t,parsOK),'r.')
% Well-fitting sinusoidal curve
plot(t(1):t(end),sfcn(t(1):t(end),parsOK),'r')
HTH
  댓글 수: 3
Morpheuskibbe
Morpheuskibbe 2019년 10월 17일
Nevermind, i realized how i borked it.
Seems to work. Thanks
Morpheuskibbe
Morpheuskibbe 2019년 10월 17일
Wow you were NOT kidding on sensitivity. For this other data '30psi.txt' i got it to fit fine by guessing 3pi/2 since its starting from the bottom, but the data "60psi.txt' that also starts from the bottom but I cant get a fit at all.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by