Calculating Breaths Per Minute from Video Data

For the very narrow question of ‘given the position of this peak in the FFT coefficients, what is the corresponding frequency?’, you can use the fftfreq function (available in FFTW).

 julia> Ts = 1. /30  # I am assuming your camera takes pictures at 30 FPS
0.03333333333333333

julia> t = 0:Ts:60
0.0:0.03333333333333333:60.0

julia> Fbreath = 20. / 60. # 20 breaths in 60 seconds
0.3333333333333333

julia> signal = sin.(2π.*t*Fbreath) .+ 0.1*rand(Float64, size(t)); # some fake data

julia> fft_sig = fft(signal);

julia> argmax(abs.(fft_sig))
21

julia> fftfreq(length(signal), 1/Ts)[21]  # second argument is the sampling rate
0.3331482509716824
1 Like