Question: I have a set of measurement which I want to model with 2nd-order difference equations (first order eqs don't model well enough).

The equation is 

$$y[n] = \alpha\_1 y[n-1] + \alpha\_2 y[n-2] + \beta\_0 x[n] + \beta\_1 x[n-1]$$

I want a generic formula for the impulse response.

I did a derivation, but being a total DSP beginner, I'm not sure whether it's correct or I'm missing some bits:

The transfer function is:

$$\begin{align}
H(z) &= \displaystyle \frac{Y(z)}{X(z)} \\
 &= \frac{\beta\_0 + \beta\_1 z^{-1}}{1 - \alpha\_1 z^{-1} - \alpha\_2 z^{-2}} \\
 &= \frac{\beta\_0 z^2 + \beta\_1 z}{z^2-\alpha\_1 z -\alpha\_2 } \\
 &= \frac{A\_1 \, z}{z-p\_1} + \frac{A\_2 \, z}{z-p\_2} \\
 &= A\_1\frac{1}{1-p\_1 z^{-1}} + A\_2\frac{1}{1-p\_2 z^{-1}} \\
\end{align}$$

where $p\_{1,2}$ are the poles and $A\_1$ and $A\_2$ can be calculated using partial fraction expansion.

Therefore the impulse response is

$h[n] = \big(A\_1 p\_1^n + A\_2 p\_2^n \big) u[n], $ 

where $u[n]$ is the discrete step function.

Is this ok?

Answer: 
Spectrograms are normally computed using the [Short-Time Fourier Transform](https://en.wikipedia.org/wiki/Short-time_Fourier_transform) (STFT), and can be done in real-time. It consists of splitting the signal into overlapped frames, using a window function (typically scaled cosine like Hann) and then computing the FFT for the frame.

The overlap and windowing is key to avoid 'spectral leakage', and sounds like what is missing in your case.
If you want more frequency resolution, you can use longer FFTs. 

In order to update with low latency (closer to "real time"), you can input short buffers often (every few milliseconds). Then combine that data with one or more previous buffers to FFT a longer data window as often as the short buffers arrive (if the CPU can keep up). Making these longer FFT buffers out of shorter incoming data buffers is called overlapping, since the longer buffers consist of partially overlapped data. Common overlaps are 50% and 75%, allowing an FFT 2X and 4X longer.

In addition, you can apply a window function as well as zero-pad the data before the FFT to remove rectangular windowing artifacts.