def desmodulando_wav(sinal_modulado): # modulando # sinal_modulado = sinal_modulado[:, 0] portadora_freq = 14000 # hz portadora = np.cos(2 * np.pi * portadora_freq * time) sinal_desmodulado = sinal_modulado * portadora X, Y = calcFFT(sinal_desmodulado, FS) fig = plt.figure(figsize=(12, 7)) plt.subplot(2, 1, 1) plt.plot(time, sinal_desmodulado) plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('Wav Modulado') # fourier plt.subplot(2, 1, 2) limite_x = 24000 plt.xlim(-limite_x, limite_x) plt.title("Fourier Do Sinal Modulado") plt.plot(X, np.abs(Y), 'red') fig.tight_layout(pad=2.0) plt.show() return sinal_desmodulado
def analyze(basename, suffix, savedir, start, no_of_samples, fft_width=512, overlap=265, height=64): for i in range(start, no_of_samples): filename = basename + str(i) + suffix sample = mat_to_nparray(filename) print i, sample.shape no_channels = sample.shape[1] for ch in range(no_channels): magnitude = calcFFT(sample[:, ch], fft_width, overlap)[:, :height] fig = plt.figure() plt.imshow(np.flipud(magnitude.transpose()), vmin=20, vmax=4000, aspect='auto', interpolation='none') fig.savefig('figures/' + savedir + '/ch' + str(ch) + '/test' + str(i) + suffix + '.png') fig, axs = plt.subplots(2, 5, figsize=(15, 6), facecolor='w', edgecolor='k')
def read_wav(audio_path): # read wav wavedata = audio_path # plot this wav file ~/audio/aaa.wav sampleRate, audioBuffer = scipy.io.wavfile.read(wavedata) #audioBuffer = audioBuffer[:, 1] duration = len(audioBuffer) / sampleRate time = np.arange(0, duration, 1 / sampleRate) # time vector X, Y = calcFFT(audioBuffer, FS) fig = plt.figure(figsize=(12, 7)) plt.subplot(2, 1, 1) plt.plot(time, audioBuffer) plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('Wav Recebido') # fourier plt.subplot(2, 1, 2) limite_x = 24000 plt.xlim(-limite_x, limite_x) plt.title("Fourier Do Sinal Original") plt.plot(X, np.abs(Y), 'red') fig.tight_layout(pad=2.0) plt.show() return audioBuffer, time
def update_voxel_data(self): self.vals = self.Data[self.pos_t,:,:,:] self.Voxel = self.Data[:,self.slice_x,self.slice_y,self.slice_z] self.VoxelZeroPad = num.zeros(32048) self.VoxelZeroPad[0:self.num_figs] = self.Voxel [self.FFTVoxel,self.frqs] = utils.calcFFT(self.Voxel,self.Fs) [self.maxtab, self.mintab ]= utils.peakdet(self.FFTVoxel,0.01) self.fftPeaks = self.maxtab[:,1] self.frqsPeaks = self.frqs[list(self.maxtab[:,0])]
def update_voxel_data(self): self.vals = self.Data[self.pos_t, :, :, :] self.Voxel = self.Data[:, self.slice_x, self.slice_y, self.slice_z] self.VoxelZeroPad = num.zeros(32048) self.VoxelZeroPad[0:self.num_figs] = self.Voxel [self.FFTVoxel, self.frqs] = utils.calcFFT(self.Voxel, self.Fs) [self.maxtab, self.mintab] = utils.peakdet(self.FFTVoxel, 0.01) self.fftPeaks = self.maxtab[:, 1] self.frqsPeaks = self.frqs[list(self.maxtab[:, 0])]
def analyze_1h(basename, suffix, savedir, start, end, fft_width=512, overlap=265, height=64): session = 0 for i in range(start, end, 6): print "session nr:",session sample = read_data_1h(basename,suffix, i) no_channels = sample.shape[1] for ch in range(no_channels): magnitude = calcFFT(sample[:,ch],fft_width,overlap)[:,:height] print "five percentile", np.percentile(magnitude,5) fig = plt.figure() plt.imshow(np.flipud(magnitude.transpose()),vmin=20 , vmax=4000, aspect='auto', interpolation='none') fig_filename = 'figures/'+savedir+'/ch'+str(ch)+'/test_1h_'+str(i)+suffix+'.png' print fig_filename fig.savefig(fig_filename) session += 1
def norm_wav(audioBuffer): normalized_wav = normalize_wav(audioBuffer) X, Y = calcFFT(normalized_wav, FS) fig = plt.figure(figsize=(12, 7)) plt.subplot(2, 1, 1) plt.plot(time, normalized_wav) plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('Wav Normalizado') # fourier plt.subplot(2, 1, 2) plt.xlim(-5000, 5000) plt.title("Fourier Do Sinal Normalizado") plt.plot(X, np.abs(Y), 'red') fig.tight_layout(pad=2.0) plt.show() return normalized_wav
def filter_wav(normalized_wav): cuttoff = 4000 # filtered_wav = low_pass_filter(normalized_wav, cuttoff, FS) X, Y = calcFFT(filtered_wav, FS) fig = plt.figure(figsize=(12, 7)) plt.subplot(2, 1, 1) plt.plot(time, filtered_wav) plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('Wav Filtrado') # fourier plt.subplot(2, 1, 2) plt.xlim(-5000, 5000) plt.title("Fourier Do Sinal Filtrado") plt.plot(X, np.abs(Y), 'red') fig.tight_layout(pad=2.0) plt.show() return filtered_wav