Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to split a signal in to chunks with the help of Blackman window using Numpy python

For a given audio signal I want it to be spitted in to 50ms chunks to perform Fourier Transform. The problem is when I use the usual split method in Numpy it adds some high frequency components due to sudden split.

So to solve this I heard we have to use a proper window.
The splitting using the numpy function is equalent to using a rectangular window which in signal processing, a not-so-clever method!

So I need help how I can use Blackman window to make my audio signal spliced in to chunks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So here is what I have used for a similar application in audio signal processing. To be exact I was making a spectrogram finder for songs. For that I also wanted to find the Fourier Transform of small chunks.

spacing = 0.1 # seconds
window_dura = 0.2 #seconds

signal_N = len(data) #length of whole audio

window_N = int(sample_rate * window_dura)
spacing_N = int(spacing * sample_rate)

#blackman nuttel window
a0,a1,a2,a3 = 0.3635819,0.4891775,0.1365995,0.0106411
xWindow = np.arange(0,window_N,1)
yWindow = a0 - a1 * np.cos(2 * np.pi * xWindow  / window_N) + a2 * np.cos(4 * np.pi * xWindow  / window_N) -a3 * np.cos(6 * np.pi * xWindow  / window_N)


n = int((signal_N - window_N) / spacing_N) # number of chunks targetable (window touches the starting point
                                                # ... total does not exceed signal length)
    
window_Array = np.zeros(shape=(n,siganl_N)) # all windows horizontally stacked
print("r3:shape",window_Array.shape)
for i in range(n):
    window_Array[i,i*spacing_N:i*spacing_N+window_N] = yWindow
    
    

Also see how these windows are aligned (only first 10 windows are displayed)

#See how the window_Array's each "window with full duration" looks like
max_plot_N = 10
fig,ax = plt.subplots(min(max_plot_N,n),1,figsize=(30,4*min(max_plot_N,n)))
for i in range(n)[:max_plot_N]:
    ax[i].plot(window_Array[i])
plt.show()

Display results of Blackman-window-array , one  at a time

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading