How to use the pyroomacoustics.hann function in pyroomacoustics

To help you get started, we’ve selected a few pyroomacoustics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LCAV / pyroomacoustics / examples / bss_example.py View on Github external
help='Creates a small GUI for easy playback of the sound samples')
    parser.add_argument('--save', action='store_true',
            help='Saves the output of the separation to wav files')
    args = parser.parse_args()

    if args.gui:
        # avoids a bug with tkinter and matplotlib
        import matplotlib
        matplotlib.use('TkAgg')

    import pyroomacoustics as pra

    ## Prepare one-shot STFT
    L = args.block
    hop = L // 2
    win_a = pra.hann(L)
    win_s = pra.transform.compute_synthesis_window(win_a, hop)

    ## Create a room with sources and mics
    # Room dimensions in meters
    room_dim = [8, 9]

    # source location
    source = np.array([1, 4.5])
    room = pra.ShoeBox(
        room_dim,
        fs=16000,
        max_order=15,
        absorption=0.35,
        sigma2_awgn=1e-8)

    # get signals
github onolab-tmu / overiva / overiva_oneshot.py View on Github external
# fix the randomness for repeatability
    np.random.seed(10)

    # set the source powers, the first one is half
    source_std = np.ones(n_sources_target)
    source_std[0] /= np.sqrt(2.0)

    SIR = 10  # dB
    SNR = (
        60
    )  # dB, this is the SNR with respect to a single target source and microphone self-noise

    # STFT parameters
    framesize = 4096
    win_a = pra.hann(framesize)
    win_s = pra.transform.compute_synthesis_window(win_a, framesize // 2)

    # algorithm parameters
    n_iter = args.n_iter

    # param ogive
    ogive_mu = 0.1
    ogive_update = "switching"
    ogive_iter = 2000

    # Geometry of the room and location of sources and microphones
    room_dim = np.array([10, 7.5, 3])
    mic_locs = semi_circle_layout(
        [4.1, 3.76, 1.2], np.pi, 0.04, n_mics, rot=np.pi / 2.0 * 0.99
    )
github LCAV / pyroomacoustics / examples / stft_block_processing.py View on Github external
from __future__ import division, print_function
import numpy as np
from scipy.signal import fftconvolve
from scipy.io import wavfile
import matplotlib.pyplot as plt
import pyroomacoustics as pra

# filter to apply
h_len = 99
h = np.ones(h_len)
h /= np.linalg.norm(h)

# parameters
block_size = 512 - h_len + 1  # make sure the FFT size is a power of 2
hop = block_size // 2  # half overlap
window = pra.hann(block_size, flag='asymmetric', length='full')  # analysis window (no synthesis window)
#window = np.ones(block_size)

# open single channel audio file
fs, audio = wavfile.read('examples/input_samples/singing_8000.wav')

# Create the STFT object
stft = pra.stft.STFT(block_size, hop=hop, analysis_window=window, channels=1)

# set the filter and the appropriate amount of zero padding (back)
if h_len > 1:
    stft.set_filter(h, zb=h.shape[0] - 1)

# collect the processed blocks
processed_audio = np.zeros(audio.shape)

# process the signals while full blocks are available
github LCAV / pyroomacoustics / examples / adaptive_filter_stft_domain.py View on Github external
"""
Length of filter in time domain =  /  * 
"""

# the unknown filters in the frequency domain
num_bands = fft_length//2+1
W = np.random.randn(num_taps,num_bands) + \
    1j*np.random.randn(num_taps,num_bands)
W /= np.linalg.norm(W, axis=0)

# create a known driving signal
x = np.random.randn(n_samples)

# take to STFT domain
window = pra.hann(fft_length)  # the analysis window
hop = fft_length//2
stft_in = pra.transform.STFT(fft_length, hop=hop,
                             analysis_window=window, channels=1)
stft_out = pra.transform.STFT(fft_length, hop=hop,
                              analysis_window=window, channels=1)

n = 0
num_blocks = 0
X_concat = np.zeros((num_bands,n_samples//hop),dtype=np.complex64)
while  n_samples - n > hop:

    stft_in.analysis(x[n:n+hop,])
    X_concat[:,num_blocks] = stft_in.X

    n += hop
    num_blocks += 1
github LCAV / pyroomacoustics / examples / beamforming_time_domain.py View on Github external
from __future__ import division, print_function

import os
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile

import pyroomacoustics as pra

# Spectrogram figure properties
figsize=(15, 7)        # figure size
fft_size = 512         # fft size for analysis
fft_hop  = 8           # hop between analysis frame
fft_zp = 512           # zero padding
analysis_window = np.concatenate((pra.hann(fft_size), np.zeros(fft_zp)))
t_cut = 0.83           # length in [s] to remove at end of signal (no sound)

# Some simulation parameters
Fs = 8000
t0 = 1./(Fs*np.pi*1e-2)  # starting time function of sinc decay in RIR response
absorption = 0.1
max_order_sim = 2
sigma2_n = 5e-7

# Microphone array design parameters
mic1 = np.array([2, 1.5])   # position
M = 8                       # number of microphones
d = 0.08                    # distance between microphones
phi = 0.                    # angle from horizontal
max_order_design = 1        # maximum image generation used in design
shape = 'Linear'            # array shape