We analyze the propagation of waves in sunspots from the photosphere to the chromosphere using time series of co-spatial Ca II H intensity spectra (including its line blends) and polarimetric spectra of Si I λ10,827 and the He I λ10,830 multiplet. From the Doppler shifts of these lines we retrieve the variation of the velocity along the line of sight at several heights. Phase spectra are used to obtain the relation between the oscillatory signals. Our analysis reveals standing waves at frequencies lower than 4 mHz and a continuous propagation of waves at higher frequencies, which steepen into shocks in the chromosphere when approaching the formation height of the Ca II H core. The observed nonlinearities are weaker in Ca II H than in He I lines. Our analysis suggests that the Ca II H core forms at a lower height than the He I λ10,830 line: a time delay of about 20 s is measured between the Doppler signal detected at both wavelengths. We fit a model of linear slow magnetoacoustic wave propagation in a stratified atmosphere with radiative losses according to Newton's cooling law to the phase spectra and derive the difference in the formation height of the spectral lines. We show that the linear model describes well the wave propagation up to the formation height of Ca II H, where nonlinearities start to become very important.