190 likes | 439 Views
Methods for Tone and Signal Synthesis. R.C. Maher ECEN4002/5002 DSP Laboratory Spring 2003. Signal Synthesis. So far in this course, we have considered signal processing : input signal sent through LTI system
E N D
Methods for Tone and Signal Synthesis R.C. Maher ECEN4002/5002 DSP Laboratory Spring 2003
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 Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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 maximal-length sequence!! yn=(a·yn-1 + c)mod M Signal Synthesis R. C. Maher
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.) Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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) Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
Wavetable Lookup Example • fs=48000 Hz, N=1024, desired fout=440 Hz • SI=1024440 / 48000 = 9.386667 Signal Synthesis R. C. Maher
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 LUAN, subtract N from LUA:integer • Fetch wavetable sample at offset LUA:integer Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
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] L L + fract L+1 Signal Synthesis R. C. Maher
Basic Wavetable Synthesizer Wavetable Gain Multiplier Sample Increment (SI) Envelope Signal Synthesis R. C. Maher
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 Signal Synthesis R. C. Maher
Musical Scale (cont.) • Example for A4=440 Hz, N=1024, fs=48000 Signal Synthesis R. C. Maher