Effacer les filtres
Effacer les filtres

How to obtain the parameters using curve fitting for a damped driven harmonic oscillator?

4 vues (au cours des 30 derniers jours)
Rajesh
Rajesh le 11 Mai 2016
Commenté : Rajesh le 12 Mai 2016
Hi,
I am trying to fit my experimental data to analytical solution to determine the parameters involved in the system behavior. I am trying to model a cantilever with a periodically varying force (sawtooth wave function with period 1.655 sec) at its tip. The system behaves as a damped driven harmonic oscillator which can be described by the differential equation:
m(d^2x/dt^2)+b(dx/dt)+kx=f(t)
The analytical solution to this differential equation is of the form:
x(t)=x_h(t)+x_p(t)
x_h(t)= exp(-alpha*time)*xm.*cos(gamma*time+phi) //homogeneous part
x_p(t)=Q*T/(2*m*wo) + {summation n=1 to N [ Q*T*(-1/(m*pi)*1/n*sin(wn*time- delta)/sqrt((wo^2-wn^2)^2+4*alpha^2*wn^2))] } //particular solution
wn=2*pi*n/T; delta=atan((2*wn*alpha)/(wo^2-wn^2));
Q=3.2700e-06 m^3/s in my case (slope of the sawtooth wave); T=1.655s; wo=sqrt(k/m); alpha=b/(2*m); gamma=sqrt(k/m-alpha^2); xi=b/(2*sqrt(m*k)); A=x(t=0); B=1/gamma*(dxdt0+xi*wo*A); xm=sqrt(A^2+B^2); phi=atan(B/A);
I am trying to use lsqcurvefit to fit the data and obtain the values of m, b and k. I get a fit (the blue curve) that goes midway through the data. What I don't understand is why the fit does not capture the oscillatory behavior in the data? nlinfit also gives a similar fit wherein the oscillations are not captured by the fit.
The above is the fit that I obtain. I have attached the matlab code that I have written.How can I obtain a better fit for my data? What other curve fitting algorithm would be more suitable?
Thanks,
Rajesh
  4 commentaires
Star Strider
Star Strider le 12 Mai 2016
The code I posted would be the same for both problems. It would implement the solution of your differential equation. You would be able to get your coefficients from the coefficients estimated by the fminsearch call (although you could use other curve-fitting functions with my objective function without changing it).
Rajesh
Rajesh le 12 Mai 2016
I took the same approach for this problem but in this case I am not able to capture the oscillations as I would have wanted. I used the same code that you had posted with minor modifications (changed the sample rate and the objective function). The fit that I get when I include 10 sine terms:
y=[-0.00209639124452783;0.00222092907403488;0.00188224939259758;0.00235956971116029;0.00106089002972300;-0.00105378965171430;-0.00201646933315159;-0.00201914901458889;-0.00221382869602618;0.00219949162253653;0.00219681194109924;-0.00212586774033806;0.00209545257822464;-0.00347522710321265;-0.00237390678464994;-0.00189658646608723;-0.00545126614752453;-0.00190194582896182;-0.00166462551039911;-0.00181130519183641;-0.00594198487327371;-0.00167266455471100;-0.00215534423614829;0.000769976082414416;-0.00177670359902288;-0.00365138328046017;-0.00255006296189747;-0.00399274264333476;-0.00111542232477205;-0.00159810200620935;-0.00188878168764664;-0.000979461369083935;-0.00290214105052123;0.00223117926804148;0.00246849958660418;0.00227381990516689;-0.00257685977627040;-0.00200353945770770;-0.000902219139144991;-0.00172089882058228;-0.00157957850201958;-0.00110225818345687;0.000767062135105835;0.00201238245366854;0.00100170277223125;0.00224702309079395;0.00118834340935666;-0.00294233627208063;-0.00520101595351793;-0.00169969563495522;-0.00151037531639252;-0.00170505499782981;2.02653207328999e-05;0.00184158563929560;0.00207890595785831;0.00236422627642102;0.00197754659498372;0.000870866913546432;0.000868187232109136;0.000289507550671842;-0.00662517213076545;-0.000963851812202746;-0.00139853149364004;-0.00140121117507733;-0.000875890856514626;0.00137742946204808;0.00180674978061079;0.00223607009917349;0.00204139041773620;0.00170271073629890;0.000500031054861610;0.00121735137342432;-3.33283080129766e-05;-0.000660007989450269;-0.00152668767088756;-0.00138536735232486;-0.00153204703376215;-0.000622726715199445;-4.94063966367379e-05;0.00114791392192597;0.000569234240488676;-0.00408944544094862;0.00190787487761408;0.00224119519617679;0.00195051551473950;0.000699835833302206;0.000985156151864910;-0.000361523529572382;-0.000844203211009676;-0.00132688289244697;-0.00152156257388426;-0.000852242255321558;-0.000278921936758851;0.000534398381803857;0.000723718700366562;0.000769039018929272;0.00172635933749197;0.00205967965605468;0.00186499997461739;0.00162232029318009;-0.000636359388257198;-0.00145503906969450;-0.00131371875113179;-0.00146039843256908;-0.000599078114006373;0.000454242204556331;0.00117156252311904;0.00145688284168174;0.00188620316024445;0.00193152347880716;0.00173684379736986;0.000678164115932568;0.000195484434495276;-0.000383195246942017;-0.00475387492837931;-0.00125255460981661;-0.00139923429125390;-0.000681913972691192;0.00104340634587152;0.000608726664434221;0.00204604698299693;0.00146736730155963;0.00141668762012234;0.00107800793868505;-0.000604671742752251;-0.00127935142418954;-0.00109003110562683;-0.00128471078706413;0.000440609531498579;0.000773929850061282;0.00177925016862399;0.00187257048718670;0.00186989080574940;0.00100321112431211;0.000760531442874814;0.000229851761437520;-0.00116482791999977;-0.00111950760143706;-0.00112218728287436;-0.000212866964311654;0.000888453354251051;0.00189377367281376;0.00213109399137647;0.00174441430993917;0.00145373462850188;-8.49450529354167e-05;-0.000423624734372709;-0.00119430441581000;-0.000956984097247299;-0.00124766377868459;-5.03434601218857e-05;0.00162697685844082;0.00200829717700353;0.00128561749556623;0.000994937814128941;-0.00102374186730835;-0.000930421548745647;-0.00107710123018294;-0.000839780911620234;0.000549539406942470;0.00126685972550518;0.00164818004406789;0.00164550036263059;1.08206811932978e-05;-0.000855859000243995;-0.000954538681681291;-0.00114921836311858;-0.00460789804455588;-9.85777259931728e-05;0.000282742592569537;0.00143206291113224;0.00176538322969495;0.00142670354825765;0.00128002386682036;0.000269344185383068;-6.93354960542276e-05;-0.000936015177491521;-0.00108269485892882;-0.000845374540366108;-0.000992054221803402;-0.000322733903240693;5.85864153220095e-05;0.000871906733884717;0.00115722705244742;0.00153854737101013;0.00172786768957284;0.00134118800813554;-0.000965491673301750;-0.000824171354739045;-0.00101885103617634;-0.000925530717613633;0.000799789600949074;0.00113310991951178;0.00185043023807449;0.00141575055663720;0.00112507087519990;0.000594391193762605;0.000159711512325310;-0.000898968169111981;-0.000709647850549276;-0.00119232753198657;0.00144499278657614;0.00153831310513884;0.00129563342370155;0.000668953742264257;-0.000725725939173041;-0.000728405620610334;-0.000587085302047625;-0.000877764983484918;-0.000160444664922216;0.000604875653640492;0.000650195972203199;0.00122351629076591;0.00150883660932861;0.00141015692789132;0.00121547724645402;0.000636797565016731;0.000346117883579438;-0.000808561797857856;-0.000571241479295151;-0.000717921160732443;0.00124739915783026;0.00162871947639297;0.00138603979495568;0.000471360113518382;0.000276680432081087;-0.000445999249356204;-0.000784678930793500;-0.000643358612230795;-0.000598038293668088;-0.00165671797510538;0.000212602343457327;0.000497922662020034;0.000975242980582735;0.00126056329914544;0.00159388361770815;0.00115920393627086;0.000436524254833566;-0.000286155426603732;-0.000672835108041024;-0.000579514789478318;-0.000630194470915611;-0.000680874152352906;-0.000491553833790198;0.000513766484772507;0.000415086803335215;0.00108440712189792;0.00122572744046062;0.00136704775902333;0.00107636807758604;0.000977688396148747;-0.000320991285288548;-0.000707670966725843;-0.000518350648163135;-0.000617030329600430;-0.000715710011037722;-0.000334389692475016;-0.000241069373912310;0.000572250944650394;0.000281571263213101;0.00104689158177581;0.00138021190033851;0.00132953221890122;0.00103885253746393;0.000508172856026634;0.000217493174589340;-0.000169186506847955;-0.00108386618828525;-0.000654545869722542;-0.000369225551159835;-0.000515905232597126;-0.00114258491403442;-0.000329264595471718;0.000196055723090990;0.000337376041653699;0.00110269636021640;0.00148401667877911;0.00128933699734182;0.000950657315904523;0.000467977634467229;-0.000158702046970067;-0.00160138172840736;-0.000452061409844653;-0.000502741091281946;-0.000697420772719240;-0.00108410045415654;0.000113219864406172;0.000446540182968878;0.000923860501531586;0.00106518082009429;0.00149450113865700;0.00105982145721970;0.000337141775782411;-1.53790565488158e-06;-0.000292217587092178;-0.000438897268529473;-0.000441576949966766;-0.000588256631404057;-0.000398936312841352;-0.000353615994278646;0.000459704324284058;0.000937024642846767;0.00122234496140947;0.00121966527997218;0.000928985598534885;0.000830305917097593;5.96262356602984e-05;-0.000663053445776993;-0.000329733127214287;-0.000524412808651584;-0.000479092490088878;-0.000433772171526171;-0.000532451852963463;-0.000343131534400758;-0.000249811215838052;0.000227509102724656;0.000800829421287363;0.000894149739850069;0.00117947005841277;0.00117679037697548;0.000886110695538187;1.94310141008935e-05;0.000304751332663601;-0.000369928348773695;-0.000516608030210989;-0.000375287711648281;-0.000377967393085574;-0.000476647074522869;-0.000431326755960163;9.39935626025417e-05;0.000763313881165251;0.000952634199727956;0.00128595451829066;0.00113927483685337;0.000848595155416075;0.000557915473978782;2.72357925414882e-05;7.25561111041911e-05;-0.000410123570333100;-0.000364803251770393;-0.000319482933207687;-0.000322162614644980;-0.000324842296082276;-0.000471521977519567;-0.000282201658956863;-9.28813403941543e-05;0.000240438978168549;0.000237759296731256;0.000523079615293963;0.000904399933856669;0.00118972025241938;0.000899040570982079;0.000224360889544787;-0.000450318791892505;-0.000452998473329798;-0.000311678154767092;-0.000314357836204389;-0.000317037517641682;-0.000799717199078972;0.000109603119483734;0.000634923438046439;0.000776243756609144;0.00106156407517185;0.00120288439373456;0.000864204712297264;0.000717525030859969;9.08453494226766e-05;0.000232165667985382;-1.05140134519115e-05;-0.000397193694889204;-0.000303873376326501;-0.000354553057763793;-0.000309232739201087;-0.000359912420638379;-0.000218592102075671;6.67282164870331e-05;1.60485350497408e-05;0.000637368853612447;0.000730689172175153;0.000824009490737859;0.00101332980930056;0.000866650127863269;0.000479970446425977;9.32907649886854e-05;-0.000101388916448612;-5.60685978859058e-05;-0.000442748279323198;-0.000253427960760490;-0.000352107642197785;-0.000306787323635078;-0.000357467005072374;-0.000120146686509667;6.91736320530417e-05;0.000594493950615750;0.000687814269178452;0.000973134587741159;0.00116245490630387;0.000775775224866572;0.000437095543429276;9.84158619919834e-05;-0.000288263819445308;-0.000386943500882604;-0.000341623182319894;-0.000344302863757190;-0.000250982545194484;-0.000349662226631776;-0.000112341908069072;7.69784104936363e-05;-0.000357701270943658;0.000503619047619045;0.000644939366181754;0.000930259684744461;0.000927580003307168;0.000876900321869873;5.82206404325788e-05;-0.000136459041004716;-0.000379138722442006;-0.000381818403879302;-0.000144498085316598;-0.000243177766753890;-0.000389857448191181;-0.000344537129628474;-5.92168110657709e-05;-0.000205896492503066;0.000559423826059643;0.000700744144622348;0.000890064463185056;0.000935384781747759;0.000596705100310467;0.000498025418873175;6.33457374358802e-05;-8.33339440014112e-05;-0.000278013625438709;-0.000424693306876000;-0.000331372988313294;-0.000238052669750588;-0.000432732351187882;-0.000243412032625178;-5.40917140624692e-05;0.000519228604500238;0.000660548923062943;0.000849869241625648;0.000847189560188355;0.000796509878751063;0.000457830197313770;2.31505158764754e-05;-0.000171529165560819;-0.000126208846998112;-0.000272888528435407;-0.000419568209872698;-0.000326247891309996;-0.000280927572747290;-0.000331607254184582;-0.000238286935621876;-0.000768966617059166;0.000332353701503535;0.000521674020066243;0.000614994338628949;0.000900314657191656;0.000705634975754365;0.000750955294317068;0.000364275612879773;-0.000118404068557518;-2.50837499948118e-05;-0.000219763431432102;-0.000270443112869402;-0.000177122794306692;-0.000179802475743985;-0.000422482157181279;-0.000329161838618576;-0.000235841520055867;-9.45212014931618e-05;-0.000145200882930454;0.000332119435632250;0.000473439754194956;0.000758760072757663;0.000804080391320369;0.000753400709883077;0.000462721028445784;0.000364041347008489;-0.000118638334428805;-7.33180158660991e-05;-0.000267997697303390;-0.000270677378740683;-0.000225357060177980;-0.000228036741615273;-0.000326716423052568;-0.000185396104489859;-9.20757859271567e-05;-4.67554673644502e-05;0.000334564851198259;0.000427885169760965;0.000521205488323671;0.000806525806886375;0.000611846125449084;0.000417166444011790;0.000222486762574496;-0.000308192918862794;-7.08726003000938e-05;-0.000457552281737386;-0.000316231963174677;-0.000222911644611971;-0.000129591326049269;-0.000228271007486561;-0.000326950688923852;-0.000233630370361146;-9.23100517984412e-05;-0.000334989733235735;0.000286330585326972;0.000619650903889678;0.000520971222452383;0.000662291541015092;0.000467611859577794;0.000368932178140502;0.000126252496703209;-0.000548427184734083;-0.000359106866171375;-0.000217786547608673;-0.000172466229045966;-0.000175145910483259;-0.000225825591920552;-0.000372505273357847;-0.000279184954795141;-0.000233864636232434;-0.000140544317669728;-0.000527223999107020;0.000286096319455684;0.000619416638018391;0.000760736956581096;0.000470057275143803;0.000803377593706513;0.000464697912269213;0.000318018230831922;2.73385493946293e-05;-0.000743341132042665;-0.000506020813479961;-0.000124700494917251;-0.000175380176354547;-8.20598577918378e-05;-0.000180739539229133;-0.000279419220666428;-0.000234098902103722;-0.000140778583541013;-0.000287458264978307;0.000237862053584401;0.000427182372147102;0.000664502690709810;0.000709823009272516;0.000611143327835224;0.000368463646397931;0.000269783964960635;-0.000836895716476659;-0.000359575397913950;-7.42550793512434e-05;-0.000556934760788541;-0.000271614442225834;-0.000178294123663125;-0.000276973805100420;-0.000279653486537713;-0.000474333167975007;-0.000525012849412303;9.63074691504039e-05;0.000237627787713112;0.000330948106275818;0.000568268424838523;0.000565588743401230;0.000514909061963937;0.000320229380526643;0.000269549699089351;7.48700176520534e-05;-0.000695809663785238;-0.000218489345222529;-0.000317169026659825;-0.000271848708097122;-0.000178528389534412;-0.000181208070971705;-0.000327887752409000;-9.05674338462923e-05;-0.000813247115283587;-0.000575926796720883;0.000237393521841825;0.000282713840404531;0.000520034158967239;0.000517354477529943;0.000322674796092648;0.000463995114655357;0.000221315433218064;7.46357517807688e-05;-0.000456043929656525;-0.000314723611093819;-0.000173403292531111;-0.000224082973968403;-0.000322762655405702;-0.000181442336842993;-0.000280122018280285;-0.000474801699717579;5.05186188451288e-05;0.000143838937407831;0.000237159255970537;0.000474479574533245;0.000663799893095953;0.000469120211658659;0.000274440530221361;0.000367760848784070;2.90811673467781e-05;-0.000789598514090516;-0.000312278195527811;-0.000362957876965107;-0.000413637558402399;-0.000224317239839691;-0.000418996921276985;-0.000181676602714281;-0.000328356284151572;-0.000763035965588867;5.02843529738407e-05;0.000335604671536548;0.000380924990099251;0.000618245308661959;0.000423565627224664;0.000612885945787373;0.000466206264350078;0.000319526582912783;0.000220846901475488;-0.000789832779961803;-0.000888512461399095;-0.000219192142836392;-0.000413871824273687;-0.000272551505710978;-0.000227231187148272;-0.000229910868585565;-0.000712590550022862;-0.000619270231460153;0.000194050087102551;4.73704056652603e-05;0.000332690724227967;0.000378011042790670;0.000519331361353379;0.000516651679916086;0.000417971998478791;0.000127292317041494;7.66126356042019e-05;-0.000742067045833092;-0.000696746727270382;-0.000219426408707677;-0.000126106090144975;-0.000368785771582265;-0.000275465453019559;-0.000806145134456852;-0.000568824815894145;-0.00681150449733144;1.81582123126604e-06;9.51361397939718e-05;0.000380456458356679;0.000185776776919388;0.000471097095482091;0.000468417414044799;0.000225737732607505;7.90580511702102e-05;2.83783697329146e-05;-7.03013117043774e-05;-0.000888980993141671;-0.000795660674578965;-0.000846340356016257;-0.000369020037453553;-0.000755699718890844;-0.000662379400328138;-0.000761059081765431;-0.000811738763202726;-4.64184446400215e-05;4.69018739226843e-05;0.000188222192485393;0.000425542511048101;0.000422862829610808;0.000468183148173511;0.000273503466736217;0.000318823785298923;0.000220144103861632;0.000121464422424336;2.27847409870409e-05;-0.000795894940450250;-0.000750574621887543;-0.000321254303324837;-0.000707933984762133;-0.000998613666199426;-0.000953293347636719;-0.000187973029074011;-4.66527105113059e-05;4.66676080513968e-05;0.000235987926614105;0.000377308245176814;0.000374628563739521;0.000371948882302228;0.000369269200864931;0.000126589519427638;0.000219909837990344;7.32301565530523e-05;-0.000217449524884244;-0.000988129206321538;-0.000702808887758831;-0.00104148856919612;-0.00104416825063342;-0.000854847932070712;-4.15276135080074e-05;5.17927050547018e-05;4.91130236174087e-05;-4.95666578198863e-05;9.17536607428189e-05;0.000281073979305524;0.000374394297868233;0.000419714616430940;0.000321034934993644;7.83552535563508e-05;0.000219675572119056;0.000120995890681764;-2.56837907555304e-05;-0.000124363472192826;-0.00103904315363012;-0.000753722835067411;-0.000804402516504704;-0.00104708219794200;-0.000281761879379292;-0.000236441560816586;-9.51212422538807e-05;-9.78009236911734e-05;-4.48060512846417e-06;0.000280839713434239;0.000326160031996946;0.000323480350559653;0.000272800669122361;0.000126120987685062;0.000123441306247769;-0.000119238375189524;2.20819433731846e-05;-0.000268597738064109;-0.000175277419501406;-0.00108995710093870;-0.00109263678237599;-0.000903316463813283;-8.99961452505790e-05;-0.000236675826687874;-0.000143355508125168;9.39648104375399e-05;0.000235285129000249;0.000280605447562952;0.000325925766125658;0.000275246084688366;0.000224566403251073;7.78867218137787e-05;2.72070403764827e-05;-7.14726410608093e-05;-7.41523224981019e-05;-0.000316832003935396;-0.000127511685372691;-0.000178191366809987;-0.00104487104824728;-0.000135550729684573;-9.02304111218634e-05;5.10899074408418e-05;-0.000143589773996456;-2.26945543374686e-06;0.000235050863128961;0.000472371181691669;0.000325691500254370;0.000371011818817077;0.000224332137379786;7.76524559424908e-05;2.69727745051983e-05;-0.000167706906932099;-0.000122386588369389;-0.00113306626980668;-7.97459512439756e-05;-0.000178425632681271;-0.000373105314118565;-0.000231784995555860;-0.000138464676993150;-0.000237144358430446;-0.000431824039867736;0.000141496278694967;0.000330816597257672;0.000376136915820379;0.000421457234383088;0.000370777552945789;0.000224097871508498;0.000173418190071205;-0.000165261491366087;-7.19411728033812e-05;-0.000122620854240677;-0.000125300535677970;-0.000223980217115265;-0.000226659898552558;-0.000181339579989848;-0.000232019261427148;-0.000186698942864438;-4.53786243017322e-05;-0.000192058305739024;9.32620128236799e-05;0.000186582331386386;0.000183902649949093;0.000325222968511798;0.000274543287074506;0.000223863605637210;-1.88160758000837e-05;0.000266504242762623;-0.000264175438674670;-0.000314855120111963;-2.95348015492591e-05;-0.000224214482986550;-8.28941644238445e-05;-0.000277573845861138;-0.000232253527298429;-0.000186933208735726;-0.000285612890173021;-0.000240292571610311;0.000141027746952395;0.000186348065515098;0.000231668384077805;0.000228988702640511;0.000226309021203219;0.000175629339765926];
t=[0.100000000000000;0.101000000000000;0.102000000000000;0.103000000000000;0.104000000000000;0.109000000000000;0.110000000000000;0.111000000000000;0.112000000000000;0.119000000000000;0.120000000000000;0.121000000000000;0.122000000000000;0.123000000000000;0.124000000000000;0.125000000000000;0.126000000000000;0.127000000000000;0.128000000000000;0.129000000000000;0.131000000000000;0.133000000000000;0.135000000000000;0.136000000000000;0.137000000000000;0.138000000000000;0.139000000000000;0.142000000000000;0.144000000000000;0.145000000000000;0.146000000000000;0.147000000000000;0.149000000000000;0.153000000000000;0.154000000000000;0.155000000000000;0.159000000000000;0.160000000000000;0.161000000000000;0.162000000000000;0.163000000000000;0.164000000000000;0.169000000000000;0.170000000000000;0.171000000000000;0.172000000000000;0.173000000000000;0.175000000000000;0.178000000000000;0.179000000000000;0.180000000000000;0.181000000000000;0.183000000000000;0.187000000000000;0.188000000000000;0.189000000000000;0.190000000000000;0.191000000000000;0.193000000000000;0.194000000000000;0.195000000000000;0.196000000000000;0.197000000000000;0.198000000000000;0.199000000000000;0.204000000000000;0.205000000000000;0.206000000000000;0.207000000000000;0.208000000000000;0.209000000000000;0.210000000000000;0.212000000000000;0.213000000000000;0.214000000000000;0.215000000000000;0.216000000000000;0.217000000000000;0.218000000000000;0.220000000000000;0.221000000000000;0.222000000000000;0.223000000000000;0.224000000000000;0.225000000000000;0.226000000000000;0.228000000000000;0.230000000000000;0.231000000000000;0.232000000000000;0.233000000000000;0.234000000000000;0.235000000000000;0.236000000000000;0.237000000000000;0.239000000000000;0.240000000000000;0.241000000000000;0.242000000000000;0.243000000000000;0.248000000000000;0.249000000000000;0.250000000000000;0.251000000000000;0.252000000000000;0.254000000000000;0.256000000000000;0.257000000000000;0.258000000000000;0.259000000000000;0.260000000000000;0.261000000000000;0.264000000000000;0.265000000000000;0.266000000000000;0.267000000000000;0.268000000000000;0.269000000000000;0.273000000000000;0.274000000000000;0.276000000000000;0.277000000000000;0.278000000000000;0.279000000000000;0.283000000000000;0.284000000000000;0.285000000000000;0.286000000000000;0.289000000000000;0.290000000000000;0.293000000000000;0.294000000000000;0.295000000000000;0.296000000000000;0.298000000000000;0.299000000000000;0.301000000000000;0.302000000000000;0.303000000000000;0.305000000000000;0.308000000000000;0.310000000000000;0.311000000000000;0.312000000000000;0.313000000000000;0.317000000000000;0.318000000000000;0.319000000000000;0.320000000000000;0.321000000000000;0.323000000000000;0.328000000000000;0.329000000000000;0.330000000000000;0.331000000000000;0.337000000000000;0.338000000000000;0.339000000000000;0.340000000000000;0.342000000000000;0.345000000000000;0.346000000000000;0.347000000000000;0.352000000000000;0.353000000000000;0.355000000000000;0.356000000000000;0.357000000000000;0.358000000000000;0.359000000000000;0.363000000000000;0.364000000000000;0.365000000000000;0.366000000000000;0.369000000000000;0.370000000000000;0.371000000000000;0.372000000000000;0.373000000000000;0.374000000000000;0.375000000000000;0.376000000000000;0.379000000000000;0.380000000000000;0.381000000000000;0.382000000000000;0.383000000000000;0.389000000000000;0.390000000000000;0.391000000000000;0.392000000000000;0.396000000000000;0.398000000000000;0.399000000000000;0.400000000000000;0.401000000000000;0.403000000000000;0.404000000000000;0.407000000000000;0.408000000000000;0.409000000000000;0.416000000000000;0.417000000000000;0.418000000000000;0.421000000000000;0.424000000000000;0.425000000000000;0.426000000000000;0.427000000000000;0.428000000000000;0.431000000000000;0.432000000000000;0.433000000000000;0.434000000000000;0.435000000000000;0.436000000000000;0.438000000000000;0.439000000000000;0.442000000000000;0.443000000000000;0.444000000000000;0.451000000000000;0.452000000000000;0.453000000000000;0.454000000000000;0.457000000000000;0.459000000000000;0.460000000000000;0.461000000000000;0.462000000000000;0.463000000000000;0.465000000000000;0.466000000000000;0.468000000000000;0.469000000000000;0.470000000000000;0.471000000000000;0.474000000000000;0.476000000000000;0.477000000000000;0.478000000000000;0.479000000000000;0.480000000000000;0.481000000000000;0.483000000000000;0.484000000000000;0.486000000000000;0.487000000000000;0.488000000000000;0.489000000000000;0.490000000000000;0.494000000000000;0.495000000000000;0.496000000000000;0.497000000000000;0.498000000000000;0.499000000000000;0.500000000000000;0.502000000000000;0.503000000000000;0.504000000000000;0.505000000000000;0.506000000000000;0.507000000000000;0.509000000000000;0.510000000000000;0.511000000000000;0.512000000000000;0.513000000000000;0.514000000000000;0.515000000000000;0.516000000000000;0.517000000000000;0.519000000000000;0.520000000000000;0.522000000000000;0.523000000000000;0.524000000000000;0.525000000000000;0.526000000000000;0.528000000000000;0.530000000000000;0.531000000000000;0.532000000000000;0.533000000000000;0.534000000000000;0.536000000000000;0.538000000000000;0.539000000000000;0.540000000000000;0.541000000000000;0.542000000000000;0.545000000000000;0.546000000000000;0.547000000000000;0.549000000000000;0.550000000000000;0.551000000000000;0.552000000000000;0.553000000000000;0.556000000000000;0.557000000000000;0.558000000000000;0.559000000000000;0.560000000000000;0.561000000000000;0.563000000000000;0.564000000000000;0.565000000000000;0.566000000000000;0.567000000000000;0.568000000000000;0.569000000000000;0.570000000000000;0.571000000000000;0.572000000000000;0.574000000000000;0.575000000000000;0.576000000000000;0.577000000000000;0.578000000000000;0.579000000000000;0.580000000000000;0.583000000000000;0.584000000000000;0.585000000000000;0.586000000000000;0.587000000000000;0.588000000000000;0.590000000000000;0.592000000000000;0.593000000000000;0.594000000000000;0.595000000000000;0.596000000000000;0.597000000000000;0.598000000000000;0.599000000000000;0.600000000000000;0.601000000000000;0.602000000000000;0.603000000000000;0.604000000000000;0.605000000000000;0.606000000000000;0.607000000000000;0.608000000000000;0.609000000000000;0.610000000000000;0.611000000000000;0.612000000000000;0.613000000000000;0.615000000000000;0.618000000000000;0.619000000000000;0.620000000000000;0.621000000000000;0.622000000000000;0.624000000000000;0.625000000000000;0.627000000000000;0.628000000000000;0.629000000000000;0.630000000000000;0.631000000000000;0.632000000000000;0.633000000000000;0.634000000000000;0.635000000000000;0.637000000000000;0.638000000000000;0.639000000000000;0.640000000000000;0.641000000000000;0.642000000000000;0.643000000000000;0.644000000000000;0.645000000000000;0.646000000000000;0.647000000000000;0.648000000000000;0.649000000000000;0.650000000000000;0.651000000000000;0.652000000000000;0.653000000000000;0.655000000000000;0.656000000000000;0.657000000000000;0.658000000000000;0.659000000000000;0.660000000000000;0.661000000000000;0.663000000000000;0.664000000000000;0.665000000000000;0.666000000000000;0.667000000000000;0.668000000000000;0.669000000000000;0.672000000000000;0.673000000000000;0.674000000000000;0.675000000000000;0.676000000000000;0.677000000000000;0.678000000000000;0.679000000000000;0.680000000000000;0.681000000000000;0.682000000000000;0.683000000000000;0.684000000000000;0.685000000000000;0.687000000000000;0.689000000000000;0.690000000000000;0.691000000000000;0.692000000000000;0.693000000000000;0.694000000000000;0.695000000000000;0.696000000000000;0.697000000000000;0.699000000000000;0.700000000000000;0.701000000000000;0.702000000000000;0.703000000000000;0.704000000000000;0.706000000000000;0.707000000000000;0.708000000000000;0.709000000000000;0.710000000000000;0.711000000000000;0.712000000000000;0.713000000000000;0.714000000000000;0.717000000000000;0.718000000000000;0.719000000000000;0.720000000000000;0.721000000000000;0.722000000000000;0.723000000000000;0.724000000000000;0.725000000000000;0.726000000000000;0.727000000000000;0.728000000000000;0.729000000000000;0.730000000000000;0.731000000000000;0.733000000000000;0.734000000000000;0.735000000000000;0.736000000000000;0.737000000000000;0.738000000000000;0.739000000000000;0.740000000000000;0.741000000000000;0.742000000000000;0.743000000000000;0.744000000000000;0.745000000000000;0.746000000000000;0.747000000000000;0.748000000000000;0.749000000000000;0.750000000000000;0.751000000000000;0.752000000000000;0.753000000000000;0.754000000000000;0.755000000000000;0.756000000000000;0.757000000000000;0.758000000000000;0.759000000000000;0.760000000000000;0.762000000000000;0.763000000000000;0.764000000000000;0.765000000000000;0.766000000000000;0.767000000000000;0.768000000000000;0.769000000000000;0.770000000000000;0.771000000000000;0.772000000000000;0.773000000000000;0.774000000000000;0.775000000000000;0.776000000000000;0.777000000000000;0.778000000000000;0.779000000000000;0.780000000000000;0.781000000000000;0.782000000000000;0.783000000000000;0.784000000000000;0.785000000000000;0.786000000000000;0.787000000000000;0.788000000000000;0.789000000000000;0.790000000000000;0.791000000000000;0.792000000000000;0.793000000000000;0.794000000000000;0.795000000000000;0.796000000000000;0.797000000000000;0.798000000000000;0.799000000000000;0.800000000000000;0.801000000000000;0.802000000000000;0.803000000000000;0.804000000000000;0.805000000000000;0.806000000000000;0.807000000000000;0.808000000000000;0.809000000000000;0.810000000000000;0.811000000000000;0.812000000000000;0.813000000000000;0.814000000000000;0.815000000000000;0.816000000000000;0.817000000000000;0.818000000000000;0.819000000000000;0.820000000000000;0.821000000000000;0.822000000000000;0.823000000000000;0.824000000000000;0.825000000000000;0.826000000000000;0.827000000000000;0.828000000000000;0.829000000000000;0.830000000000000;0.831000000000000;0.832000000000000;0.833000000000000;0.834000000000000;0.835000000000000;0.836000000000000;0.837000000000000;0.838000000000000;0.839000000000000;0.840000000000000;0.841000000000000;0.842000000000000;0.843000000000000;0.844000000000000;0.845000000000000;0.846000000000000;0.847000000000000;0.848000000000000;0.849000000000000;0.850000000000000;0.851000000000000;0.852000000000000;0.853000000000000;0.854000000000000;0.855000000000000;0.856000000000000;0.857000000000000;0.858000000000000;0.859000000000000;0.860000000000000;0.861000000000000;0.862000000000000;0.863000000000000;0.864000000000000;0.865000000000000;0.866000000000000;0.867000000000000;0.868000000000000;0.869000000000000;0.870000000000000;0.871000000000000;0.872000000000000;0.874000000000000;0.875000000000000;0.876000000000000;0.877000000000000;0.878000000000000;0.879000000000000;0.880000000000000;0.881000000000000;0.882000000000000;0.883000000000000;0.884000000000000;0.885000000000000;0.886000000000000;0.887000000000000;0.888000000000000;0.889000000000000;0.890000000000000;0.891000000000000;0.892000000000000;0.893000000000000;0.894000000000000;0.895000000000000;0.896000000000000;0.897000000000000;0.898000000000000;0.899000000000000;0.900000000000000;0.901000000000000;0.902000000000000;0.903000000000000;0.904000000000000;0.905000000000000;0.906000000000000;0.907000000000000;0.908000000000000;0.909000000000000;0.910000000000000;0.911000000000000;0.912000000000000;0.913000000000000;0.914000000000000;0.915000000000000;0.916000000000000;0.917000000000000;0.918000000000000;0.919000000000000;0.920000000000000;0.921000000000000;0.922000000000000;0.923000000000000;0.924000000000000;0.925000000000000;0.926000000000000;0.927000000000000;0.928000000000000;0.929000000000000;0.930000000000000;0.931000000000000;0.932000000000000;0.933000000000000;0.934000000000000;0.935000000000000;0.936000000000000;0.937000000000000;0.938000000000000;0.939000000000000;0.940000000000000;0.941000000000000;0.942000000000000;0.943000000000000;0.944000000000000;0.945000000000000;0.946000000000000;0.947000000000000;0.948000000000000;0.949000000000000;0.950000000000000;0.951000000000000;0.952000000000000;0.953000000000000;0.954000000000000;0.955000000000000;0.956000000000000;0.957000000000000;0.958000000000000;0.959000000000000;0.960000000000000;0.961000000000000;0.962000000000000;0.963000000000000;0.964000000000000;0.965000000000000;0.966000000000000;0.967000000000000;0.968000000000000;0.969000000000000;0.970000000000000;0.971000000000000;0.972000000000000;0.973000000000000;0.974000000000000;0.975000000000000;0.976000000000000;0.977000000000000;0.978000000000000;0.979000000000000;0.980000000000000;0.981000000000000;0.982000000000000;0.983000000000000;0.984000000000000;0.985000000000000;0.986000000000000;0.987000000000000;0.988000000000000;0.989000000000000;0.990000000000000;0.991000000000000;0.992000000000000;0.993000000000000;0.994000000000000;0.995000000000000;0.996000000000000;0.997000000000000;0.998000000000000;0.999000000000000;1.00000000000000;1.00100000000000;1.00200000000000;1.00300000000000;1.00400000000000;1.00500000000000;1.00600000000000;1.00700000000000;1.00800000000000;1.00900000000000;1.01000000000000;1.01100000000000;1.01200000000000;1.01300000000000;1.01400000000000;1.01500000000000;1.01600000000000;1.01700000000000;1.01800000000000;1.01900000000000;1.02000000000000;1.02200000000000;1.02300000000000;1.02400000000000;1.02500000000000;1.02600000000000;1.02700000000000;1.02800000000000;1.02900000000000;1.03000000000000;1.03100000000000;1.03200000000000;1.03300000000000;1.03400000000000;1.03500000000000;1.03600000000000;1.03700000000000;1.03800000000000;1.03900000000000;1.04000000000000;1.04100000000000;1.04200000000000;1.04300000000000;1.04400000000000;1.04500000000000;1.04600000000000;1.04700000000000;1.04800000000000;1.04900000000000;1.05000000000000;1.05100000000000;1.05200000000000;1.05300000000000;1.05400000000000;1.05500000000000;1.05600000000000;1.05700000000000;1.05800000000000;1.05900000000000;1.06000000000000;1.06100000000000;1.06200000000000;1.06300000000000;1.06400000000000;1.06500000000000;1.06600000000000;1.06700000000000;1.06800000000000;1.06900000000000;1.07000000000000;1.07100000000000;1.07200000000000;1.07300000000000;1.07400000000000;1.07500000000000;1.07600000000000;1.07700000000000;1.07800000000000;1.07900000000000;1.08000000000000;1.08100000000000;1.08200000000000;1.08300000000000;1.08400000000000;1.08500000000000;1.08600000000000;1.08700000000000;1.08800000000000;1.08900000000000;1.09000000000000;1.09100000000000;1.09200000000000;1.09300000000000;1.09400000000000;1.09500000000000;1.09600000000000;1.09700000000000;1.09800000000000;1.09900000000000;1.10000000000000];
Fs=1000; Fn = Fs/2;
L = size(t,1);
y = detrend(y);
fty = fft(y)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
Wp = 5/Fn;
Ws = 20/Fn;
Rp = 1;
Rs = 25;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn);
[sos,g] = tf2sos(b,a);
freqz(sos, 2048, Fs)
yf = filtfilt(sos,g,y);
yu = max(yf);
yl = min(yf);
yr = (yu-yl);
yz = yf-yu+(yr/2);
zt = t(yz(:) .* circshift(yz(:),[1 0]) <= 0);
per = 2*mean(diff(zt));
ym = mean(y);
fit = @(b,x) b(1) .* exp(b(2).*x) .* (sin(2*pi*x./b(3) + 2*pi/b(4)) + sin(2*pi*x./b(5) + 2*pi/b(6)) + sin(2*pi*x./b(7) + 2*pi/b(8)) + sin(2*pi*x./b(9) + 2*pi/b(10)) + sin(2*pi*x./b(11) + 2*pi/b(12))...
+sin(2*pi*x./b(13) + 2*pi/b(14)) + sin(2*pi*x./b(15) + 2*pi/b(16)) + sin(2*pi*x./b(17) + 2*pi/b(18)) + sin(2*pi*x./b(19) + 2*pi/b(20)) + sin(2*pi*x./b(21) + 2*pi/b(22)))+ b(23);
fcn = @(b) sum((fit(b,t) - yf).^2);
s = fminsearch(fcn, [yr; -1; per; -1; per; -1; per; -1; per; -1; per; -1; per; -1; per; -1; per; -1; per; -1; per; -1; ym]);
xp = linspace(min(t),max(t),819);
figure(1)
plot(t,y,'b')
hold on
plot(t,yf,'y', 'LineWidth',2)
plot(xp,fit(s,xp), 'r', 'LineWidth',1.5)
hold off
xlabel('Time')
ylabel('Amplitude')
legend('Original Data', 'Lowpass-Filtered Data', 'Fitted Curve')
The analytical solution is for a complete time period and to get a good fit I had to excluded the data from both the ends. I am not sure how to obtain the original set of parameters that I wanted to fit since now the time interval is changed. Any suggestions?
Thanks

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by