Giter Site home page Giter Site logo

audiostim's Introduction

AudioStim

Simple Python class to generate artificial auditory stimuli such as pure tones, chirps and noise.

Requirements

The dependencies are:

  • numpy,
  • scipy and
  • matplotlib.

To install them if you do not already have them installed, you can run the following in a terminal/command window from the directory containing requirements.txt:

pip install -r requirements.txt

Usage

The example.py file describes how to create a Stimulus object:

from Stimulus import Stimulus

# Define length of stimulus in seconds and sampling rate in samples/second
length = 0.1
fs = 44100

# Initialise Stimulus object with given length and sampling rate
s = Stimulus(length, fs)

Generating the stimulus

You can choose to generate:

  • a pure tone
    # Define frequency of tone
    f = 1000
    
    # Generate tone
    s.pure_tone(f)
  • a frequency sweep
    # Define start and stop frequency of sweep
    start = 0
    stop = 1000
    
    # Generate frequency sweep
    s.chirp(start,stop)
  • silence
    # Generate silence
    s.silence()
  • white noise
    # Generate white noise
    s.noise()

Note that the methods pure_tone(), chirp(), silence() and noise() will overwrite whatever is stored as data in the object.

Adding Stimulus objects

You can add Stimulus objects with the + operator. In the example, we generate a noise stimulus and add it to a stimulus with silence.

# Generate noise and silence and add them together
fs = 44100

noise_length = 0.1
silence_length = 1


noise = Stimulus(noise_length, fs)
noise.noise()

silence = Stimulus(silence_length, fs)
silence.silence()

stim = silence + noise

Repeating a stimulus

A stimulus can be repeated with the * operator:

repeated_stim = 3 * stim

Visualising the stimulus

You can plot the waveform and the spectrogram of the stimulus using the plot_waveform() and plot_spectrogram() methods respectively:

repeated_stim.plot_waveform()
repeated_stim.plot_spectrogram()

Saving the stimulus

Stimuli can be saved into wav files using the save_wav() method:

repeated_stim.save_wav('filename.wav')

By default, stimuli are as 16-bit files, but it is possible to select 32-bit:

repeated_stim.save_wav('filename.wav', bit_depth='32')

audiostim's People

Contributors

sihao avatar

Stargazers

Hobart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.