<commit_before>import wave
import scipy.io.wavfile as sciwave
from scipy.fftpack import fft
import math
import numpy as np
import pyaudio
import pylab

# ========= (2) RECEIVED SIGNAL =========

Fs, a = sciwave.read('90-180pool1.wav')
a = np.array(a)
a = a / (2.0**15 - 1.0)

####### Parametres modifiables ###

M = 1;                       # Number of sources
N = 2;                       # Number of microphones(on doit avoir M <= N - 1)
dist = .08;                  # Distance between adjacent microphones(en m)
# c = 346.287;               # Speed of sound in air(en m/s)
c = 1500;                    # Speed of sound in water
f = 15000;                   # Signal frequency(en Hz)

lfft = 1024 * 1;             # Number of data points for FFT in a snapshot
K = math.floor(np.size(a[:,0]) / lfft); # Number of frequency snapshots(multiple of lfft)
L = int(K * lfft);                # Number of data snapshots recorded by receiver
y = a[0:L,:];                # Truncated signal(contient nbre entier de snapshots)

T = 1 / Fs;
rx=np.linspace(-(N-1)/2.0,(N-1)/2.0,N).reshape(N,1); # Assume uniform linear array (on peut avoir elevation si on fait array rectangulaire avec min 3 hydrophones)
ry=np.zeros((N,1),float);
rz=np.zeros((N,1),float);
r = np.concatenate((rx,ry,rz),axis=1); # Assume uniform linear array

## Forme complexe du signal recu
df = float(Fs)/float(lfft)/1.0;                 # frequency grid size
F = np.arange(0,Fs/1,df);
X=np.zeros((int(lfft),int(N),int(K)),dtype='complex');
for ih in range (0,int(N)):
    for iv in range (0,int(K)):
        pos=iv*lfft;
        tmp=y[pos:pos+lfft,ih];
        X[:,ih,iv]=fft(tmp);


# Find the closest frequency from the discrete frequency vector resulted from FFT
values=abs(F-f);
mf=np.amin(values);
mi=np.argmin(values)
f0=F[mi];

x0=np.zeros((int(N), int(K)),dtype='complex');
for ih in range (0,int(N)):
    for iv in range (0,int(K)):
        x0[ih,iv]=X[mi,ih,iv]; # signal complexe

## Common parameters for all algo

# Sample covariance matrix
Rxx = np.dot(x0,x0.conj().T)/L;
print(Rxx)
# Search directions
AzSearch = np.linspace(0,180,181); # Azimuth values to search
ElSearch = np.zeros(AzSearch.shape); # Simple 1D example


# Corresponding points on array manifold to search
kSearch = math.pi*np.array([np.cos(np.radians(AzSearch))*np.cos(np.radians(ElSearch)), np.sin(np.radians(AzSearch))*np.cos(np.radians(ElSearch)), np.sin(np.radians(ElSearch))]);
ASearch = np.exp(-1j*np.dot(r,kSearch));

###############################################################################################################
## Bartlett or Conventional Beamforming

#Bartlett spectrum
Zbf=[]
for i in range (0,np.size(AzSearch)):
    Z=(ASearch[:,i].conj().T).dot(Rxx).dot(ASearch[:,i]);
    Zbf.append(abs(Z));
<commit_msg>ajout Adaptation algo pour des signaux rééls<commit_after>import wave
import scipy.io.wavfile as sciwave
from scipy.fftpack import fft
import math
import numpy as np
import pyaudio
import pylab

# ========= (2) RECEIVED SIGNAL =========

Fs, a = sciwave.read('90-180pool1.wav')
a = np.array(a)
a = a / (2.0**15 - 1.0)     # Normalisation des donnees (valeurs sur 16 bits)

####### Parametres modifiables ###

M = 1;                       # Number of sources
N = 2;                       # Number of microphones(on doit avoir M <= N - 1)
dist = .08;                  # Distance between adjacent microphones(en m)
# c = 346.287;               # Speed of sound in air(en m/s)
c = 1500;                    # Speed of sound in water
f = 15000;                   # Signal frequency(en Hz)

lfft = 1024 * 1;             # Number of data points for FFT in a snapshot
K = math.floor(np.size(a[:,0]) / lfft); # Number of frequency snapshots(multiple of lfft)
L = int(K * lfft);                # Number of data snapshots recorded by receiver
y = a[0:L,:];                # Truncated signal(contient nbre entier de snapshots)

T = 1 / Fs;
rx=np.linspace(-(N-1)/2.0,(N-1)/2.0,N).reshape(N,1); # Assume uniform linear array (on peut avoir elevation si on fait array rectangulaire avec min 3 hydrophones)
ry=np.zeros((N,1),float);
rz=np.zeros((N,1),float);
r = np.concatenate((rx,ry,rz),axis=1); # Assume uniform linear array

## Forme complexe du signal recu
df = float(Fs)/float(lfft)/1.0;                 # frequency grid size
F = np.arange(0,Fs/1,df);
X=np.zeros((int(lfft),int(N),int(K)),dtype='complex');
for ih in range (0,int(N)):
    for iv in range (0,int(K)):
        pos=iv*lfft;
        tmp=y[pos:pos+lfft,ih];
        X[:,ih,iv]=fft(tmp);


# Find the closest frequency from the discrete frequency vector resulted from FFT
values=abs(F-f);
mf=np.amin(values);
mi=np.argmin(values)
f0=F[mi];

x0=np.zeros((int(N), int(K)),dtype='complex');
for ih in range (0,int(N)):
    for iv in range (0,int(K)):
        x0[ih,iv]=X[mi,ih,iv]; # signal complexe

## Common parameters for all algo

# Sample covariance matrix
Rxx = np.dot(x0,x0.conj().T)/L;

# Search directions
AzSearch = np.linspace(0,180,181); # Azimuth values to search
ElSearch = np.zeros(AzSearch.shape); # Simple 1D example


# Corresponding points on array manifold to search
kSearch = math.pi*np.array([np.cos(np.radians(AzSearch))*np.cos(np.radians(ElSearch)), np.sin(np.radians(AzSearch))*np.cos(np.radians(ElSearch)), np.sin(np.radians(ElSearch))]);
ASearch = np.exp(-1j*np.dot(r,kSearch));

###############################################################################################################
## Bartlett or Conventional Beamforming

#Bartlett spectrum
Zbf=[]
for i in range (0,np.size(AzSearch)):
    Z=(ASearch[:,i].conj().T).dot(Rxx).dot(ASearch[:,i]);
    Zbf.append(abs(Z));

{'fraction_non_alphanumeric': 0.19616545357713475, 'fraction_numerical': 0.026983845197940705, 'mean_word_length': 3.510808646917534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7053328', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1988, 'n_words': 516}