Number of occurrences of k consecutive 1's in a binary string of length n (containing only 1's and 0's) Say a sequence $\{X_1, X_2,\ldots ,X_n\}$ is given, where $X_p$ is either one or zero ($0 < p < n$). How can I determine the number of strings, which do contain at least one occurrence of consequent $1$'s of length $k$ ($0 < k < n$). 
For example, a string $\{1, 0, 1, 1, 1, 0\}$ is such a string for $n = 6$ and $k = 3$.
Here I have found an answer for arbitrary $n$ and $k = 2$, ($k = 1$ is trivial), but I need a more general answer for any natural number  $k$ smaller than $n$. 

Here is an approach based upon generating functions. We start considering words  with no consecutive equal characters at all.
These words are called Smirnov words or Carlitz words. (See example III.24 Smirnov words from Analytic Combinatorics by Philippe Flajolet and Robert Sedgewick for more information.) 
A generating function for the number of Smirnov words over a binary alphabet is given by
\begin{align*}
\left(1-\frac{2z}{1+z}\right)^{-1}\tag{1}
\end{align*}

Generating function: $G_k(z)$
In order to set up for the binary strings we are looking for, we replace occurrences of $1$ in a Smirnov word by runs of $1$ with length up to $k-1$ assuming $k\geq 2$.  This  corresponds to a substitution
  \begin{align*}
z&\longrightarrow z+z^2+\cdots+z^{k-1}=\frac{z\left(1-z^{k-1}\right)}{1-z}\tag{2}\\
\end{align*}
   Since there are no restrictions to $0$ at all, we replace occurrences of $0$ in a Smirnov word by any runs of $0$'s with length $\geq 1$.
  \begin{align*}
z&\longrightarrow z+z^2+z^3+\cdots=\frac{z}{1-z}\tag{3}\\
\end{align*}
We obtain by substituting (2) and (3) in (1) a generating function $A_k(z)$
  \begin{align*}
A_k(z)&=\left(1-\frac{\frac{z}{1-z}}{1+\frac{z}{1-zt}}-\frac{\frac{z\left(1-z^{k-1}\right)}{1-z}}{1+\frac{z\left(1-z^{k-1}\right)}{1-z}}\right)^{-1}\\
&=\frac{1-z^k}{1-(t+1)z+tz^{k+1}}\tag{4}\\
\end{align*}
  counting all binary words having no 1-runs of length $k$. To obtain a generating function which counts all binary words having at least one 1-run of length $k$, we take the generating function 
  \begin{align*}
\frac{1}{1-2z}=1+2z+4z^2+8z^3+\cdots
\end{align*}
  which counts all binary words and subtract $A_k(z)$ from it.

We conclude from (4) a generating function counting all binary words having at least one 1-run of length $k$ is $G_k(z)$ with
\begin{align*}
\color{blue}{G_k(z)}&\color{blue}{=\frac{1}{1-2z}-\frac{1-z^k}{1-2z+z^{k+1}}}\\
&\color{blue}{=\frac{(1-z)z^k}{(1-2z)(1-2z+z^{k+1]})}}
\end{align*}

Explicit formula:
We derive from $G_k(z)$ an explicit formula of the wanted numbers. Denoting with $[z^n]$ the coefficient of $z^n$ in a series we obtain using the geometric series expansion
\begin{align*}
[z^n]\frac{1}{1-2z+z^{k+1}}&=[z^n]\sum_{j=0}^\infty z^j(2-z^k)^j\tag{5}\\
&=\sum_{j=0}^n [z^{n-j}](2-z^k)^j\tag{6}\\
&=\sum_{j=0}^{\left\lfloor\frac{n}{k}\right\rfloor}[z^{kj}](2-z^k)^{n-kj}\tag{7}\\
&=\sum_{j=0}^{\left\lfloor\frac{n}{k}\right\rfloor}[z^{kj}]
\sum_{l=0}^{n-kj}\binom{n-kj}{l}(-z^k)^l2^{n-kj-l}\\
&=\sum_{j=0}^{\left\lfloor\frac{n}{k}\right\rfloor}\binom{n-kj}{j}(-1)^j2^{n-(k+1)j}\tag{8}
\end{align*}

Comment:


*

*In (5) we use the binomial series expansion.

*In (6) we use the linearity of the coefficient of operator and apply the rule $[z^{p-q}]F(z)=[z^p]z^qF(z)$. We also set the upper limit of the sum to $n$ since the exponent of $z^{n-j}$ is non-negative.

*In (7) we change the order of summation $j\rightarrow n-j$ and respect that only multiples of $k$ give a contribution to the sum.

*In (8) we select the coefficient of $z^{kj}$.
The sum in (8) gives the first part of the formula we need. We can use it to derive the second part

\begin{align*}
[z^n]\frac{z^k}{1-2z+z^{k+1}}&=[z^{n-k}]\frac{1}{1-2z+z^{k+1}}\\
&=\sum_{j=0}^{\left\lfloor\frac{n-k}{k}\right\rfloor}\binom{n-k(j+1)}{j}(-1)^j2^{n-k-(k+1)j}
\end{align*} 
Finally putting all together we conclude the number of binary words of length $n$ containing 1-runs of length $k\geq 2$ is
  \begin{align*}
\color{blue}{[z^n]G_k(z)=2^n-\sum_{j=0}^{\left\lfloor\frac{n}{k}\right\rfloor}
\left(\binom{n-kj}{j}-\frac{1}{2^k}\binom{n-k(j+1)}{j}\right)(-1)^j2^{n-(k+1)j}}
\end{align*}

We can also use $G_k(z)$ to derive a recurrence relation for the coefficients $[z^n]G_k(z)$. Due to the specific structure of 
\begin{align*}
G_k(z)&=\frac{1}{1-2z}-A_k(z)\\
\end{align*}
it seems to be more convenient to derive a recurrence relation for the coefficients $a_n=[z^n]A_k(z)$ and subtract them from $2^n$.

Recurrence relation:
We obtain by coefficient comparison for $k\geq 2$
  \begin{align*}
A_k(z)&=\frac{1-z^k}{1-2z+z^{k+1}}\\
\left(1-2z+z^{k+1}\right)A_k(z)&=1-z^k\\
\color{blue}{a_n-2a_{n-1}+a_{n-k-1}}&\color{blue}{=}
\color{blue}{\begin{cases}
1&\qquad n=0\\
-1&\qquad n=k\\
0&\qquad n \neq 0,k
\end{cases}}
\end{align*}
  where we set $a_n=0$ if $n<0$.

Example: $k=2$
In case of $k=2$ we obtain
\begin{align*}
A_2(z)&=\frac{1-z^2}{1-2z+z^3}\\
&=1+2z+3z^2+5z^3+8z^4+13z^5+21z^6+\cdots
\end{align*}
and finally
\begin{align*}
G_2(z)&=\frac{1}{1-2z}-\frac{1-z^2}{1-2z+z^3}\\
&=z^2+3z^3+8z^4+19z^5+43z^6+94z^7+\cdots
\end{align*}
