% calculate motor speed % input file: time differences between encoder ticks in micro seconds % 2024-06-27 Christoph M. x=csvread("timeBetweenEncoderTicks_us_3p4V_560mA.txt"); #x=csvread("timeBetweenEncoderTicks_us_3p4V_600mA.txt"); # create time axis from delta t's t=cumsum(x)/1e6; # remove values less than 1000us because the are disturbances cleanIdx=x<1000; t(cleanIdx)=[]; x(cleanIdx)=[]; # moving average over 24 ticks to smooth encoder slot variations wndw = 24; %# sliding window size x = filter(ones(wndw,1)/wndw, 1, x); #remove run in of moving average t=t(wndw:end); x=x(wndw:end); if 0 #subplot(2,1,1); plot(x); xlabel("n"); ylabel("dt [us]"); ylim([0,10000]); end if 1 #subplot(2,1,2); encoderTicks=24; measuredFrequency_Hz=1e6./x; rounds_per_sec=measuredFrequency_Hz/encoderTicks RPM=rounds_per_sec*60 plot(t,RPM); title("motor speed supply 3.4V on/off") xlabel("time [s]"); ylabel("RPM"); ylim([0,2000]) grid; end