<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Let's check the normalization of the whitening filter.
The inverse ASD should be multiplied by the sqrt(2 / sample_rate) in order to get the variance of the whitened time domain data to be one.
Step1:  Now let's try applying a weighting in the frequency domain that doesn't change the TD variance.
We just fix the sum of squares of the filter in the TD to be 1.
<ASSISTANT_TASK:>
Python Code:
invasd = sqrt(2./srate)/sqrt(shaped_psd1)
invasd[0] = 0.
whitener = sig.hann(seglen*srate)*roll(irfft(invasd), seglen*srate/2)
wtest = TimeSeries(sig.convolve(shaped_noise2, whitener, mode='same')[8*srate:-8*srate],
                       sample_rate=srate)
p1 = wtest.psd(seglen).plot()
mean(wtest.psd(seglen)) / (2./srate)
mean(wtest**2)
Explanation: Let's check the normalization of the whitening filter.
The inverse ASD should be multiplied by the sqrt(2 / sample_rate) in order to get the variance of the whitened time domain data to be one.
End of explanation
filt1 = sig.firwin2(seglen*srate, [0.,0.25,0.5,0.75,1.], [0.,0.5,1.,0.5,0.], window='hann')
filt1 /= sqrt(sum(filt1**2))
weight_test1 = TimeSeries(sig.convolve(noise, filt1, mode='same')[8*srate:-8*srate],
                       sample_rate=srate)
var(weight_test1)
filt2 = gen_filter.copy()
filt2 /= sqrt(sum(filt2**2))
weight_test2 = TimeSeries(sig.convolve(noise, filt2, mode='same')[8*srate:-8*srate],
                       sample_rate=srate)
var(weight_test2)
filt12 = sig.hann(seglen*srate)*roll(irfft(abs(rfft(filt1)*rfft(filt2))), seglen*srate/2)
weight_test12 = TimeSeries(sig.convolve(noise, filt12, mode='same')[8*srate:-8*srate],
                       sample_rate=srate)
plt.plot(freqs, abs(rfft(filt1)*rfft(filt2)))
plt.plot(filt12)
sum(filt1**2)
sum(abs(rfft(filt1))**2)/(seglen*srate/2.)
Explanation: Now let's try applying a weighting in the frequency domain that doesn't change the TD variance.
We just fix the sum of squares of the filter in the TD to be 1.
End of explanation
<END_TASK>