why square() cannot work with cftool
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
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
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 个评论
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!