Background information
Bit flips
Given a bit string, we say that bit flip happens when $0$ changes to $1$ or $1$ changes to $0$.
To find bit flips, we can shift the string by $1$ and xor that new string with the original one. The resulting string will have $1$ in the positions where bit flips happened in the original bit string.
Having this new representation, we can repeat this operation to get the number of bit flips on the bit string of bit flips. It somewhat resembles the second derivative (because we track the change of the change). Let's call it the second-order bit flip.
Let's consider the following example: $$ 01010001 $$
It's bit flip representation is: $$ 1111001 $$
Then the second order bit flip representation is: $$ 000101 $$
Counting the number of $1$s in every bit string above gives us the number of ones in the original bit string $k = 3$, the number of bit flips $m_1 = 5$, and the number of second-order bit flips $m_2 = 2$.
Counting bit strings with a certain number of bit flips
Now let's say we have a bit string of length $n$ with $k$ ones and $m$ bit flips. Can we count the number of such strings? Let's call this $A(n,k,m)$. Bit flips split the whole sequence into $m+1$ blocks, each filled with only $1$s or $0$s. Also a block of $1$s has to be followed by a block of $0$s. Depending on whether $m$ is even or odd, the number of blocks for $1$s and $0$s is either equal or differs by exactly $1$. Now, let's say that $m = 2m' + 1$, then we need to split our $1$s and $0$s into exactly $m' + 1$ blocks each. This can be done via $\binom{k - 1}{m'}$ for $1$s and $\binom{n-k-1}{m'}$ for $0$s. We have 2 ways of choosing the first block. Putting it all together: $$ A(n,k,2m'+1) = 2\binom{k - 1}{m'}\binom{n - k - 1}{m'} $$ For $m = 2m'$, we have $m' + 1$ blocks of one kind and $m'$ blocks of another kind. Choosing whether $1$ or $0$s get more blocks determines the very first block. Putting it all together: $$ A(n,k,2m') = \binom{k - 1}{m' + 1}\binom{n - k - 1}{m'} + \binom{k - 1}{m'}\binom{n - k - 1}{m' + 1} $$
Because of the nature of these counts, we can also say that: $$ \sum\limits_{m=0}^{n} A(n,k,m) = \binom{n}{k} $$
The actual problem
Counting bit strings with a certain number of second-order bit flips
Extending the previous problem to include second-order bit flips, we can now say that we have $m_1$ bit flips and $m_2$ second-order bit flips and we want to find $B(n,k,m_1,m_2)$, i.e. the number of bit strings of length $n$ with $k$ ones, $m_1$ bit flips and $m_2$ second-order bit flips.
Again, we can expect that: $$ \sum\limits_{i=0}^{n} B(n,k,m,i) = A(n,k,m) $$
I tried writing a recurrence for this problem and solve it via generating functions: Finding coefficient in a complex multivariable generating function. However, the complexity of the intermediate steps is quite hard and I abandoned that route (there are might be tricks that I'm not aware of that can make it easier).
I'd really appreciate any insights into how to solve this family of problems. Of course, it would be amazing to find a closed form solution for the N-order bit flips: $F(n,k,m_1,...,m_N)$, but any pointers are welcome. Many thanks in advance!
PS I might have reinvented some terms, so please correct me if you spotted familiar concepts.