This is very normal and predictable when computing the PSD using the Welch method (as employed in this code). Please check the following link (Part: Estimating PSD with the Welch method) to find out the reason for this observation.
https://sapienlabs.org/factors-that-impact-power-spectrum-density-estimation/
So the code is okay and nothing wrong with your results. There are other ways of filtering like Wavelet filters which tune the window length for different frequency bands.