I have a data vector which consists of calibrated pressure at each sampled point in time. I have also taken this signal, applied a filter bank to it using a butterworth filter with passbands according to third octave (i.e. band center frequency at 25, 31.5, 40,...,20,000), and for each band calculated $20\log(p_{rms}/p_{ref})$ where $p_{rms}$ is the root mean squared pressure for the resulting filtered signal in each band, and $p_{ref} =2\times10^{-5}$ Pa. This should give me the third octave "spectrum".
I now wish to calculate the total sound pressure level (SPL). I thought first I could say that $SPL = 20\log(p/p_{ref})$ where $p$ is just the root mean squared value of the entire data vector.
To compare I thought I would then calculate the same quantity but this time starting from my third octave data. I would then hope to get the same answer by adding logarithmically (i.e. adding the rms values from each band and then converting to dB) the dB values from each third octave band. However this did not give matching results.
I therefore suspect I am not converting from third octave to a single SPL quantity correctly, since my first calculation of SPL seems very straightforward. Am I missing something here? For instance does each third octave band need to be scaled by the frequency bin? This would imply I have some sort of density in third octave, but im not sure.