**Sampling and Generation**

In mathematics a signal is a real function of a real variable f(t). In electronics it represents the evolution of a voltage (or a current) over the time.

Simplified diagram to generate an arbitrary signal v(t) from a digital format v(i) is the following:

First of all, the information is available in digital format, inside a file in the vector numbers format (samples). Through a memory buffer, samples move to a digital-to-analog converter that produces a voltage signal to output to the external world, after an appropriate amplification stage. Shannon's theorem states that the sampling frequency fs must satisfy the following relation:

*fs ≥ 2B*, where B is the absolute band of the output signal. Details on the sampling theorem can be found in literature or also at:wikipedia

Even if the DAC can assure high sampling frequency, the absolute band of the signal that has to be generated depends on the performances of the output stage of the audio card. Because it's designed for sound applications, it's equipped with an amplifier with a 200Hz-20KHz bandwidth (in the ideal case). It must be also taken into account that the output signal will be distorted in amplitude and phase, more around the upper cutoff frequency. All that limits the generation of signals having with bandwidth lower than about 10KHz.

At this point, the most important issues are:

1- to generate a file with the signal in the digital format.

2- to setup a hw/sw sysytem able to perform the digital to analog conversion chain (DAC).

**Matlab and the PC sound card**

A possible solution for this problem consists to use Matlab with a PC sound card. Matlab is a numerical calculation environment based on matrix structures. It's able to easily generate a time function (unidimensional vector). Furthermore, through specialized functions, Matlab is able to generate a .wav format of the signal compatible with all sound player for PC through the sound card. Often, depending on the specific situations, it's necessary an auxilary output stage for the audio signal conditioning.

Matlab supplies different internal functions to generate a waveform. Most of these require a preliminary statement of a time vector. Considering a sample frequency of fs[Hz] it's possible to produce a time vector by writing: *t=linspace(0, end, end*fs *. This command generates a time vector from zero to end second, divided in end*fs points.

The source code to generate a 20Hz, 2 seconds tone is:

*t=linspace(0, 2, 2*10000)*

*y=sin(2*pi*20*t)*

*plot(t, y)*

*wavwrite(y, 10000, prova.wav)*

The function wavwrite(y,fs,'nomefile') generates an audio nomefile.wav file from the y vector sampled at the fs frequency.

**Example: DTMF tones generation**

As example, we consider the generation of DTMF tones of the telephon keyboard. Dual-Tone Multi-Frequency is a decoding method used in the telephony to code numerical digits by means of sound signals in the audio band. The DTMF keyboard consists of a 4x4 matrix where each row represents a low frequency while each column represents an high frequency. For example, pressing the button one are sent two waves at 697 and 1209 Hz. The Multifrequency term comes from the simultaneous use of two waves.

The following source allows to generate with Matlab a 12 seconds dtmf.wav file that reproduces, at interval of one second, the sequence of the DTMF tones of the buttons:

0-1-2-3-4-5-6-7-8-9-*-#

%------------------------------ %-- EXAMPLE OF DTMF GENERATION %------------------------------ l=12; %-- signal length in second fs=10000; %-- sampling frequency in HZ t=linspace(0,l,l*fs); %-- generating the time axis fc1=697; %-- frequencies fc2=770; fc3=852; fc4=941; fr1=1209; fr2=1336; fr3=1477; y0 = sin(2*pi*fc3*t) + sin(2*pi*fr2*t); % 0 y1 = sin(2*pi*fc1*t) + sin(2*pi*fr1*t); % 1 y2 = sin(2*pi*fc1*t) + sin(2*pi*fr2*t); % 2 y3 = sin(2*pi*fc1*t) + sin(2*pi*fr3*t); % 3 y4 = sin(2*pi*fc2*t) + sin(2*pi*fr1*t); % 4 y5 = sin(2*pi*fc2*t) + sin(2*pi*fr2*t); % 5 y6 = sin(2*pi*fc2*t) + sin(2*pi*fr3*t); % 6 y7 = sin(2*pi*fc3*t) + sin(2*pi*fr1*t); % 7 y8 = sin(2*pi*fc3*t) + sin(2*pi*fr2*t); % 8 y9 = sin(2*pi*fc3*t) + sin(2*pi*fr3*t); % 9 y_start = sin(2*pi*fc3*t) + sin(2*pi*fr1*t); % * y_canc = sin(2*pi*fc3*t) + sin(2*pi*fr3*t); % # y=zeros(1,length(t)); k=0; s=length(y)-1; s=s+1; for i=1:s if k = s/12 && k = ((2*s)/12) && k = ((3*s)/12) && k = ((4*s)/12) && k = ((5*s)/12) && k = ((6*s)/12) && k = ((7*s)/12) && k = ((8*s)/12) && k = ((9*s)/12) && k = ((10*s)/12) && kUmberto Calari, EOStech Srl