# User-Defined Waveforms

Sim4Life T-Neuro provides pre-defined, parametrized monopolar, bipolar and sinusoidal pulse waveforms. However there is often the need to use complex, customized waveforms. The user can use the the 'user defined' option to import text files defining the waveform profile.

The following Matlab/Octave code illustrates how such a waveform text file can be created e.g. to define an amplitude-modulate sinusoidal signal with a 1kHz carrier frequency and a 10Hz modulation frequency.

``````clear all; close all;

% Waveform Parameters
t=linspace(0,1,60000);  % Creates Time Vector
f=1000;                 % Frequency Carrier [Hz]
df=10;                  % Frequency Modulation [Hz]

% Create the Waveform
v=0.5*sin(2*pi*f*t)+0.5*sin(2*pi*(f+df)*t);

% Visualize the Waveform
figure; plot(t(1:8000)*1000,v(1:8000))
xlabel('Time (ms)'); ylabel('Waveform [AU]')
data=[t*1000 ; v];

% Write as txt file to be imported in Sim4Life
dlmwrite('waveform.txt',data,'\t')
``````

Thanks! This is really what I want to know. This should be included in HTML manual.

@kj Here there is the equivalent Python code. Sometimes it is easier to have all code produced within Sim4Life.

``````import numpy as np

## Waveform Parameters
t=np.linspace(0,1,60000);  # Creates Time Vector
f=1000                    # Frequency Carrier [Hz]
df=10;                     # Frequency Modulation [Hz]

## Create the Waveform
v=0.5*np.sin(2*np.pi*f*t)+0.5*np.sin(2*np.pi*(f+df)*t);

# Creates The Data Structure
data=np.array([t*1000,  v])

## Write as txt file to be imported in Sim4Life
np.savetxt(filename, data, delimiter=' ',fmt='%1.4f')
``````