# -*- coding: utf-8 -*- """ Inicialização para o 1º trabalho de laboratório de Sinais e Sistemas Created on Wed Feb 26 18:38:20 2014 @author: lba """ def sistema1(x): sx = size(x) delay = floor(.25 * samplingrate) # Delay of 0.5s, measured in samples y = zeros(sx+delay) # Reserve enough space for the delayed signal y[0:sx] = x y[delay : sx+delay] += x / 2 y = append(zeros(delay), y) return y def u(t): return float_(t>=0) # float_ is the numpy standard function for conversion to float (equivalent to float64) def tplot(x): duration = (size(x) - 1) / samplingrate t = timevar(duration) # Time variable local to this function plot(t,x) def timevar(duration): tlim = duration / 2 t = arange(-tlim * samplingrate, tlim * samplingrate + .1, 1) / samplingrate # This gives exact values for integer values of t return t def play(x): x = clip(x, -1, 1) # If |x|>1 this would give a strong distortion wavwrite('play.wav', samplingrate, (32767*x).astype(int16)) PlaySound('play.wav',0) # Set the second argument to 1 to returm immediately to the calling program removefile('play.wav') def seqsin(*arg): """Generate a sequence of sinusoids with specified frequencies and durations. """ if mod(len(arg),2) != 0: print('seqsin: Number of arguments must be even') return t1 = .001 * samplingrate # Duration, in samples, of the initial taper t2 = .01 * samplingrate # Duration, in samples, of the final taper y = zeros(0) # Initialize output array pos = 0 # Initialize position in which we are in the output array for nseg in range(int(len(arg) / 2)): freq = arg[2*nseg] duration = arg[2*nseg+1] * samplingrate # Duration of this segment, in samples i = arange(t1) y = append(y, .5 * (1 + cos(pi / t1 * (i - t1))) * sin(2 * pi * freq / samplingrate * i)) i = arange(t1, duration-t2) y = append(y, sin(2 * pi * freq / samplingrate * i)) i = arange(duration-t2, duration) y = append(y, .5 * (1 + cos(pi / t2 * (i - duration + t2 + 1))) * sin(2 * pi * freq / samplingrate * i)) pos += duration return y # import pdb from numpy import * from matplotlib.pyplot import plot from os import remove as removefile from scipy.io.wavfile import write as wavwrite from scipy.io.wavfile import read as wavread #from winsound import PlaySound from soundapi import * from sistema2 import * samplingrate = 16000 x = wavread('fala.wav') fala = array(x[1]) / 32767 # x[0] contains the sampling rate of the wav file, which is 16000 for this file del x print("\n\nSinais e Sistemas - 1º trabalho de laboratório: inicialização concluída.\n")