Spectral analysis of second order difference equations