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 Center および File ExchangeCurve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by