Revision 6:fd0f9d0615b2 9-dsp-block-by-block.py

View differences:

9-dsp-block-by-block.py
1 1
import numpy as np
2
import pylab as plt
2 3
from scikits.audiolab import wavread
3 4

  
4 5
#################################################
......
9 10

  
10 11

  
11 12
#################################################
12
#### CALCULATE RMS OF EACH AUDIO BLOCK ####
13
####### CALCULATE RMS OF EACH AUDIO BLOCK #######
13 14
#################################################
14 15

  
15
hop_size = 2048                             # set hop size
16
frame_size = 4096                           # set frame size
16
hop_size = 512                             # set hop size
17
frame_size = hop_size*2                     # set frame size
17 18
frame = np.zeros(frame_size)                # initialise frame with zeros
18 19
window = np.hanning(frame_size)             # create window of the same length as the hop size
19 20

  
......
24 25
for n in range(0,x.size-hop_size,hop_size):
25 26
    
26 27
    # extract a segment of length hop_size
28
    frame = x[n:n+hop_size]                               
29
        
30
    # calculate RMS
31
    rms_val = np.sqrt(np.power(frame,2).mean())
32
    
33
    # add amplitude to our numpy array
34
    rms = np.append(rms,rms_val)
35

  
36
print rms
37

  
38
""" I AM THE OVERLAP VERSION
39
# run through signal frame by frame 
40
for n in range(0,x.size-hop_size,hop_size):
41
    
42
    # extract a segment of length hop_size
27 43
    buffer = x[n:n+hop_size]                               
28 44
    
29 45
    # add new segment to frame, shifting back samples of frame
......
36 52
    rms = np.append(rms,rms_val)
37 53

  
38 54
print rms
39
    
55
"""
56

  
57
plt.plot(rms)
58
plt.title("RMS")
59
plt.xlabel("time")
60
plt.ylabel("value")
61
plt.show()
40 62
                                   
41 63
 

Also available in: Unified diff