Signal Generation Techniques - Montana State University

Download Report

Transcript Signal Generation Techniques - Montana State University

Methods for Tone and Signal
Synthesis
R.C. Maher
ECEN4002/5002 DSP Laboratory
Spring 2002
Signal Synthesis
• So far in this course, we have considered
signal processing: input signal sent through
LTI system
• For signal synthesis, we generally do not
have an explicit input signal: output is
generated by an algorithm
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
2
Applications of Synthesis
• Synthesis is useful in DSP systems for
– Communications signals (modulation, coherent
detection, modem tones, etc.)
– Test signals (function generator, noise test
signals, transfer function measurement)
– Warning and notification tones
– Music synthesis
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
3
General Synthesis Types
• Algorithmic synthesis
– Pseudo-random signals (noise with specified
statistical properties)
– Periodic signals using a mathematical formula
(transcendental functions, discrete summation)
• Look-up table synthesis
– Signal synthesized by reproducing samples
from data in memory: a wavetable
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
4
Random Signal Generation
• Want an algorithm to produce a sequence of
numbers that appear to be chosen randomly
• Usually use a periodic sequence with a
period sufficiently long that the repetition is
not a problem: sequence is pseudo-random
• Method applicable to DSP chips is the
linear congruential algorithm
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
5
Linear Congruential Method
• A “cheap” and not particularly rigorous method to
make pseudo-random sequences
• Uses a recursive method and a modulo
• For numbers between 0  y  (M-1), select y0
(“seed”) and values for multiplier a, displacement
c, and modulus M. Not all choices give maximallength sequence!!
yn=(a·yn-1 + c)mod M
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
6
Periodic Signal Algorithm
• Generate the signal by implementing a
discrete-time formula
• Works well for square, pulse, triangle,
sawtooth waveforms, but these are
generally not bandlimited
• If sufficient processing power available, can
approximate an arbitrary function (cosine,
exponential, etc.)
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
7
Digital Sinusoid Generator
• Consider a filter with h[n]=Rn sin(w0n) u(n),
which is a causal decaying sinusoid for
0<R<1, and a pure sinusoid for R=1
• w0=2pf/fs
• Start with impulse input
R sin(w0 ) z 1
H ( z) 
1  2R cos(w0 ) z 1  R 2 z 2
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
8
Stored Signal Synthesis
• Concept: fill a delay line with one cycle of
the desired waveform, then “loop” the
signal over and over to produce the
extended output signal
• Vary the frequency by decimation /
interpolation of the stored samples
• Vary the amplitude by multiplying a slowly
varying envelope function
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
9
Wavetable Frequency Control
• Assume table is length N, holds one period
of the signal, and the sample rate is fs
• Output frequency for entire table is fs/N
New sample every 1/fs;
Table frequency fs/N
Wavetable (N)
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
10
Frequency Control (cont.)
• To get a different output frequency from the
same stored wavetable, define a sample
increment (SI) and a lookup accumulator
(LUA).
• SI is typically a fixed-point number (integer
part and fractional part) defined by
f out
SI  N 
fs
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
11
Frequency Control (cont.)
• Lookup accumulator (LUA) has an integer
part and a fractional part. The integer part
is modulo-N : counts zero to N-1, then rolls
over to zero.
• At each sample time, add SI to LUA, then
use integer part of LUA as lookup index
into stored wavetable. Can use fractional
part of LUA for inter-sample interpolation
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
12
Wavetable Lookup Example
• fs=48000 Hz, N=1024, desired fout=440 Hz
• SI=1024440 / 48000 = 9.386667
LUA
0.000000
9.386667
18.773334
28.160001
37.546668
46.933335
56.320002
...
994.986702
1004.373369
1013.760036
1023.146703
8.533370
17.920037
ECEN4002 Spring 2002
Signal Synthesis
Index
0
9
18
28
37
46
56
...
994
1004
1013
1023
8
17
R. C. Maher
13
Implementation on DSP
• Load a buffer with one cycle (length N) of the
waveform
• Define SI:integer and SI:fraction variables
• Define LUA:integer and LUA:fraction variables
• For each sample:
–
–
–
–
Add SI:fractional to LUA:fractional
Add with carry SI:integer to LUA:integer
If LUAN, subtract N from LUA:integer
Fetch wavetable sample at offset LUA:integer
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
14
Details to watch out for…
• Wavetable lookup (resampling) with SI>1
will cause aliasing if wavetable contains
components above fs/(2·SI)
• Choosing N to be a power-of-2 makes LUA
modulo a simple masking operation
• Frequency resolution determined by number
of fractional bits in LUA
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
15
Linear Interpolation
• LUA contains desired “location” of next output
sample. If LUA:fraction  0, we need to
interpolate the table.
• Ideally, need to do bandlimited (Shannon)
interpolation, but often settle for cheap linear
interpolation between adjacent table samples
y[L+1]
y[L]
y[ L  fract]  y[ L]  fract  ( y[ L  1]  y[ L])
L
L + L+1
fract
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
16
Basic Wavetable Synthesizer
Wavetable
Sample
Increment
(SI)
ECEN4002 Spring 2002
Gain
Multiplier
Envelope
Signal Synthesis
R. C. Maher
17
Musical Frequency Scale
• Most Western music uses a “Well-Tempered
Scale” for the 12 notes of the diatonic scale
– Scale based on note A = 440 Hz
– All other A note frequencies are multiples of 2n,
where n is an integer (A=110, 220, etc.)
– Other notes (B, B#, C, etc.) related by 2k/12
– Factor 21/12 = 1.059463
ECEN4002 Spring 2002
Signal Synthesis
R. C. Maher
18
Musical Scale (cont.)
• Example for A4=440 Hz, N=1024, fs=48000
Note
A3
A#3
B3
C4
C#4
D4
D#4
E4
F4
F#4
G4
G#4
A4
A#4
B4
C5
ECEN4002 Spring 2002
Semitone
-12
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
Signal Synthesis
Hz
220.0000
233.0819
246.9417
261.6256
277.1826
293.6648
311.1270
329.6276
349.2282
369.9944
391.9954
415.3047
440.0000
466.1638
493.8833
523.2511
SI
4.6933
4.9724
5.2681
5.5813
5.9132
6.2648
6.6374
7.0321
7.4502
7.8932
8.3626
8.8598
9.3867
9.9448
10.5362
11.1627
R. C. Maher
19