why square() cannot work with cftool

조회 수: 11 (최근 30일)
Cheerful
Cheerful 2012년 7월 10일
hi
i have generated a data-series below: x=1:0.01:100; F=square(0.5*x);
then i invoke cftool, under the custom equations, i have the equation: square(b*x)
and run the curve-fitting. It could not fit, and the estimated b always follow the initial value of b. The R-square always negative.
why square() could not used under the custom equations? it should work fine like sine() functions?
thank you

답변 (3개)

Tom Lane
Tom Lane 2012년 7월 10일
I suspect this is because the derivative of the function is always 0 or +/-Inf. The optimizer that tries to perturb the inputs in order to find a minimum sum of squared residuals needs a smoother function. For instance, if it perturbed the coefficient a little, it would see no difference in the results:
>> F = square(.5*t);
>> isequal(F,square(.50001*t))
ans =
1
  댓글 수: 1
Cheerful
Cheerful 2012년 7월 10일
Hi Tom
thanks for the very good answer. May I know how to model a square-wave function in order to use min sum of squared residual? I am trying to estimate the period and pulse-width of a data-sets.

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


Star Strider
Star Strider 2012년 7월 10일
If you want to estimate the period and pulse width of data sets, and the data sets (or a subset of each of them) are square wave pulse trains, I suggest something simple such as ‘diff’:
pulses = diff([0; data]); % For a column vector. The leading ‘0’ preserves the indices so it will match those of ‘data’
Search (use ‘find’) for the positive spikes to mark the beginning of the square waves, then do the same to find the next negative spike to mark the end, to give you the pulse width. The times between positive spikes will give you the period.
This isn't elegant, but if I understand your question correctly, it should give you what you want.
  댓글 수: 2
Cheerful
Cheerful 2012년 7월 10일
yes. that is a very good suggestion. However, actually my real problem is more challenging. Just that I try to break it into simpler parts.
I have a similar data series at the bottom of figure 3. The next step is to estimate the parameters of the inputs at the top of figure 3. That is the period and duty cycle of the sine wave. Hence I try to fit this PWM to the data series using least squares.
thanks alot
Star Strider
Star Strider 2012년 7월 10일
If you have the Signal Processing Toolbox, see if the ‘demod’ function will do what you need. It has a ‘pwm’ option. The only approach I can think of is a ‘for’ loop that calculates each pulse width as it goes by determining the distance between a positive-going pulse and the next negative-going pulse. There must be a better way.

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


Wayne King
Wayne King 2012년 7월 10일
In R2012, There are a number of new measurement functions in Signal Processing Toolbox. Among them are several applicable to pulse waveforms:
pulsewidth.m, pulsesep.m, pulseperiod.m, and dutycle.m

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by