Exemplo n.º 1
0
def genSpecSines_p(ipfreq, ipmag, ipphase, N, fs):
    """
    Generate a spectrum from a series of sine values.
    iploc, ipmag, ipphase: sine peaks locations, magnitudes and phases
    N: size of the complex spectrum to generate; fs: sampling rate
    returns Y: generated complex spectrum of sines
    """

    Y = np.zeros(N, dtype = complex) # initialize output complex spectrum
    hN = N/2 # size of positive frequency spectrum
    for i in range(0, ipfreq.size): # generate all sine spectral lobes
        loc = N * ipfreq[i] / fs # it should be in range ]0,hN-1[
        if loc == 0 or loc > hN-1: continue
        binremainder = round(loc)-loc
        lb = np.arange(binremainder - 4, binremainder+5) # main lobe bins to read
        lmag = UF.genBhLobe(lb) * 10**(ipmag[i]/20) # lobe magnitude of the complex exponential
        b = np.arange(round(loc) - 4, round(loc) + 5)
        for m in range(0, 9):
            if b[m] < 0: # peak lobe crosses DC bin
                Y[-b[m]] += lmag[m] * np.exp(-1j * ipphase[i])

            elif b[m] > hN: # peak lobe crosses Nyquist bin
                Y[b[m]] += lmag[m] * np.exp(-1j * ipphase[i])

            elif b[m] == 0 or b[m] == hN: # peak lobe in the limits of the spectrum
                Y[b[m]] += lmag[m]*np.exp(1j * ipphase[i]) + lmag[m]*np.exp(-1j * ipphase[i])

            else: # peak lobe in positive freq. range
                Y[b[m]] += lmag[m] * np.exp(1j * ipphase[i])

        Y[hN+1:] = Y[hN-1:0:-1].conjugate() # fill the negative part of the spectrum
        return Y
Exemplo n.º 2
0
import numpy as np
import sys, os
sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)),
                 '../../software/models/'))
import utilFunctions as UF

bins = np.array([-4, -3, -2, -1, 0, 1, 2, 3]) + .5
X = UF.genBhLobe(bins)
import numpy as np
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sms-tools-master/software/models/'))
import utilFunctions as UF
import dftModel as DFT
import matplotlib.pyplot as plt
from scipy.signal import blackmanharris, triang, get_window
from scipy.fftpack import ifft

bins = np.array([-4, -3, -2, -1, 0, 1, 2, 3])
X = UF.genBhLobe(bins)      #blackman harris is the sum of four sinc functions,
                            #this function finds the values of a blackman harris
                            #curve for given bins

(fs, x) = UF.wavread('sms-tools-master/sounds/oboe-A4.wav')
M = 501
#N = 512
Ns = 512
hNs = int(Ns/2)
H = int(Ns/4)
t = -70  #min threshold from the peak for other peaks
w = get_window('hamming', M)
x1 = x[int(.8*fs):int(.8*fs) + M]
mX, pX = DFT.dftAnal(x1, w, Ns)
peaks = UF.peakDetection(mX, t)

ipeaks, iMag, iPhase = UF.peakInterp(mX, pX, peaks)
ipfreq = fs * ipeaks / float(Ns)

#ipfreq = np.array([3000.0, 4000.0])
#iMag = np.array([0.0, 0.0])
Exemplo n.º 4
0
import numpy as np
import matplotlib.pyplot as plt
import sys, os

from scipy.signal import get_window

sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), '../sms-tools/software/models/') )
import dftModel as DFT
import utilFunctions as UF

bins = np.array([-4, -3, -2, -1, 0, 1, 2, 3])
X = UF.genBhLobe(bins)