Code, containing relevant data, for Pons, "The self-oscillation paradox in the flight motor of D. melanogaster", Journal of the Royal Society Interface, 2023.
Three subfolders are contained. 
In this file "the SI" refers to the Supporting Information for that paper. 


/ symbolic computation ------------------------------------------------------------------------------------------------------------------------------------
Containing computer symbolic computation of key expressions. Scripts in MATLAB r2022b, annotated. Within:

system_1_PEA_quadratic.m			Critical c-values for the PEA system with quadratic damping, as per §4.1 of the manuscript.

system_2_PEA_quadratic_plus_structural.m	Critical c-values for the PEA system with quadratic and constant structural damping, as per §4.3 of the
						manuscript and §5.1 of the SI.

system_3_PEA_linear.m				Critical d-values for the PEA system with linear damping, as per §4.3 of the manuscript and §5.1 of the SI.

system_4_hybrid_quadratic.m			Critical c-values for the hybrid PEA-SEA system with quadratic damping, as per §4.3 of the manuscript
						and §5.2 of the SI.

resonant_frequencies.m				Resonant frequencies of PEA system with linear or quadratic damping, as per §5.2 of the manuscript.


/ drosophila self-oscillation  ----------------------------------------------------------------------------------------------------------------------------
Containing self-oscillation analyses of drosophila data. Scripts and data files in MATLAB r2022b, annotated. Within:

get_fill.m					Custom plot tool script
main_analysis_drosophila.m			Main analysis script, generating paper figures, using data from Pons et al. (2023) and other sources
MP_response_calculations.m			Short set of calculations using the response data of Machin and Pringle (1959)
MP_work_loop_fitting.m				Process for estimating negative loss tangent via fitting to Machin and Pringe's (1959) work loop data
TIIR_estimation.m				Time-independent impulse response (TIIR) estimation process, applied to the data of Loya et al. (2022)

MP_case_A_data.mat				Data generated from calculation for Machin and Pringle (1959) case A
						Containing variables:
							xexp		displacement data from Machin and Pringle (1959)
							fexp		force data from Machin and Pringle (1959)
							r_est		estimated value of r (neg. loss tangent) from work loop fit
							xyt_est  	fitted profile (force, column 2 vs. displacement, column 2) based on estimated r

MP_case_B_data.mat				" case B
						Containing variables:
							xexp		displacement data from Machin and Pringle (1959)
							fexp		force data from Machin and Pringle (1959)
							est_r		estimated value of r (neg. loss tangent) from work loop fit
							est_E		estimated value of E (linear stiffness) from work loop fit
							wt		dimensionless time (in no. periods) for fitted profile
							xt		normalised sine signal, xt = cos(wt)
							fit_ft  	fitted force based on estimated r and cubic properties
							xplot		normalised basis over xt, xplot = linspace(-1, 1, 101);

MP_case_C_data.mat				" case C
						Containing the same variables as case B.

MP_case_D_data.mat				" case D
						Containing the same variables as case B.

MP_compiled_case_data.mat			Compiled data based on calculation from Machin and Pringle (1959)
						Containing variables:
							la_obs		lambda values (response freq. over structural natural freq.) observed by 
									Machin and Pringle (1959) for each of cases A-D (structure under variable)

							r_obs		r values (neg. loss tanged) fitted to the work loops recorded by Machin
									and Pringle (1959) for each of cases A-D (structure under variable)

							zeta		damping ratios for the structural oscillators of Machin and Pringle (1959)
									for each of cases A-D (structure under variable)

Pons_B&B_dataset.mat				Dataset of Pons et al. (2023) in raw form.
						Containing variables:

							dt		time step size for relevant wing kinematic profiles, ivp.phi_TWO_normalised
							Om		consistent angular frequency of the wingbeat (applies to all data)
							ivp		structure containing raw calculation results from the dataset of Pons et al. (2023).
									The relevant subvariables used in this study are:

									ivp.phi_TWO_normalised	normalised ([0 1]) wing stroke angle profile for the 33 
												biological-type datasets (see paper SI for citations)

									ivp.MT_TWO		total moment, inertial and aerodynamic, at the wing root,
												in nNm, for the 33 biological-type datasets (see paper
												SI for citations)

							musc_kro	structure containing work-loop data from Kronert et al. (2018)
									The relevant subvariables used in this study are:

									musc_kro.strain_basis_norm	normalised ([-1 1]) basis over strain for work loop
									musc_kro.upper_stress_double	stress (w.r.t. strain) of upper arc of muscular work loop
									musc_kro.lower_stress_double	stress (w.r.t. strain) of lower arc of muscular work loop
									
							musc_ram	structure containing work-loop data from Ramanath et al. (2011)
									Same subvariables (mutatis mutandis) as musc_kro

							musc_swa  	structure containing work-loop data from Swank (2012)
									The relevant subvariables used in this study are:

									musc_swa.double.norm_strain_11	normalised ([-1 1]) basis over strain for work loop
									musc_swa.double.force_hi	stress (w.r.t. strain) of upper arc of muscular work loop
									musc_swa.double.force_lo	stress (w.r.t. strain) of lower arc of muscular work loop
		
							musc_krz	unused structure of work-loop data from additiona literature study.


/ drosophila wingbeat fitting  ----------------------------------------------------------------------------------------------------------------------------
Containing wingbeat load requirement fitting. Scripts and data files in MATLAB r2022b, annotated. Within:

deriv_dim2.m					Custom finite-difference script
fitting_wingbeat_loads.m			Main analysis script, generating wingbeat load fit properties and figures, using data from Pons et al. (2023)
get_polygon_envelope.m				Custom plot tool script

fit_data.csv					Output of fit properties automatically generated by fitting_wingbeat_loads.m
						Each row is one of the 33 biological-type datasets, with columns:
						1	Citation for aerodynamic data (in shorthand, see "Citations used in fit_data.csv" below or table S1 in the SI)
						2	Citation for inertial data  (in shorthand, see "Citations used in fit_data.csv" below or table S1 in the SI)
						3	Fitted beta value (quadratic damping coefficient)
						4	Goodness-of-fit for this beta value
						5	Fitted zeta value (linear damping ratio)
						6	Goodness-of-fit for this zeta value

Pons_B&B_dataset.mat				Dataset of Pons et al. (2023) in raw form, with relevant variables specified above.

References
----------

Loya A K, Van Houten S K, Glasheen B M and Swank D M (2022) Shortening deactivation:
quantifying a critical component of cyclical muscle contraction Am. J. Physiol.-Cell
Physiol. 322 C653–65 DOI: 10.1152/ajpcell.00281.2021

Machin K E and Pringle J W S (1959) The physiology of insect fibrillar muscle - II
Mechanical properties of a beetle flight muscle Proc. R. Soc. Lond. B Biol. Sci. 151 204–
25 DOI: 10.1098/rspb.1959.0060

Pons A, Perl I, Ben-Dov O, Maya R and Beatus T (2023) Solving the thoracic inverse
problem in the fruit fly Bioinspir. Biomim. 18 046002 DOI: 10.1088/1748-3190/accc23

Ramanath S, Wang Q, Bernstein S I and Swank D M (2011) Disrupting the Myosin
Converter-Relay Interface Impairs Drosophila Indirect Flight Muscle Performance
Biophys. J. 101 1114–22 DOI: 10.1016/j.bpj.2011.07.045

Swank D M (2012) Mechanical analysis of Drosophila indirect flight and jump muscles
Methods 56 69–77 DOI: 10.1016/j.ymeth.2011.10.015

Citations used in fit_data.csv
------------------------------

Citations for aerodynamic data:

Meng 17: Meng X, Liu Y, Sun M. 2017 Aerodynamics of Ascending Flight in Fruit Flies. J. Bionic Eng. 14, 75–87. (doi:10.1016/S1672-6529(16)60379-7)
Meng 15: Meng XG, Sun M. 2015 Aerodynamics and vortical structures in hovering fruitflies. Phys. Fluids 27, 031901. (doi:10.1063/1.4914042)
Shen *: Shen C, Liu Y, Sun M. 2018 Lift and power in fruitflies in vertically-ascending flight. Bioinspir. Biomim. 13, 056008. (doi:10.1088/1748-3190/aad212)
Yao and Yeo: Yao Y, Yeo KS. 2018 Longitudinal free flight of a model insect flyer at low Reynolds number. Comput. Fluids 162, 72–90. (doi:10.1016/j.compfluid.2017.12.004)
Mujires: Muijres FT, Elzinga MJ, Melis JM, Dickinson MH. 2014 Flies Evade Looming Targets by Executing Rapid Visually Directed Banked Turns. Science 344, 172–177. (doi:10.1126/science.1248955)

Citation for inertial data:

Ben-Dov: Ben-Dov O, Beatus T. 2022 Model-Based Tracking of Fruit Flies in Free Flight. Insects 13, 1018. (doi:10.3390/insects13111018)
Beatus: Beatus T, Cohen I. 2015 Wing-pitch modulation in maneuvering fruit flies is explained by an interplay between aerodynamics and a torsional spring. Phys. Rev. E 92, 022712. (doi:10.1103/PhysRevE.92.022712)
Roni Maya: Maya R, Lerner N, Ben-Dov O, Pons A, Beatus T. 2023 A hull reconstruction-reprojection algorithm for pose estimation of free-flying fruit flies. J. Exp. Biol., article in advance, jeb242872.(doi:10.1242/jeb.245853)

