Home

ADSP-2181 Experiments - ECE

image

Contents

1. wait for interrupt and loop forever interrupt service routine starts here enable secondary register set wait idle jump wait input_samples ena sec_reg sample processing algorithm ay0 dm N ar ay0 1 decrement N until zero dm N ar if eq jump stop do not stop until N iterations mx1 Al my1 dm i5 m5 my1 s1 sin 2 pi f1 t mr mx1 my1 ss mr Al s1 mx1 A2 my1 dm i6 m6 my1 s2 sin 2 pi f2 t mr mr mx1 my1 rnd mr x Al s1 A2 s2 if 1 use 0 to skip filtering cfir M 14 m4 12 m2 mri input from mr1 output in mri endif write samnples to codec 4 EXPERIMENTS 31 dm tx_buf 1 mri left output sample dm tx_buf 2 mrl right output sample rti stop include lt c adi_dsp macros end dsp gt wrapup This program generates internally a sum of two sinusoids and filters them through the cfir macro The input signal is x t Az sin 27tf t A gt sin 2Ttf gt t where the two sinusoidal terms are generated from a common wavetable which is cycled every c and cz samples such that f els f 2 3 The wavetable is filled with one period of length D that is by the numbers 2 s n Asin lt meo LD We use D 800 so that the smallest frequency that can be generated is fs D
2. wait for interrupt and loop forever interrupt service routine starts here enable secondary register set wait idle jump wait input_samples ena sec_reg sample processing algorithm A t Aenv sin 2 pi fenv t AC t sin 2 pi f t wavgen i5 m5 Aenv cenv ax1 wavgen i6 m6 axl c mx1 write output samples to codec dm tx_buf 1 mx1 left output sample dm tx_buf 2 mx1 right output sample 4 EXPERIMENTS 67 return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup FM Modulation The third program fm dsp illustrates FM modulation in which the frequency of a sinusoid is itself varying sinusoidally The generated signal is of the form x t sin 27rf t t Because the frequency of the sinusoid is passed into the wavetable generator via the parameter c we define the frequency f t in the form f t c t fs D where c t Co Am sin 2Ttfimt We choose the modulation depth Am 0 3Cg so that c t varies sinusoidally between the limits 0 7C lt c t lt 1 3co and therefore the frequency will vary in the limits 0 7fo lt f t lt 1 3f0 where fo Cofs D The center frequency is fo 200 Hz corresponding to Cy 100 and Am 0 3Co 30 The same wavetable sinetb1 hex
3. wait for interrupt and loop forever interrupt service routine starts here enable secondary register set wait idle jump wait input_samples ena sec_reg read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm wavgen i6 m6 A c mr mr1 A square wave myl AO mr mr mx1 my1 rnd mr x AO mike A square if mv sat mr srl mr1 jump nofilter uncomment to bypass filter pre scale x down compute output y input from srl output in sri post scale y up sr ashift mr1 by ex hi ccan M 14 m4 12 m2 ea eb sri sr ashift srl by ex hi EXPERIMENTS 78 write samples to codec nofilter dm tx_buf 1 srl left output sample dm tx_buf 2 srl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The program notch13 dsp implements the filter H 3 Z in its direct form The coefficients already fit in 1 15 format and do not need any further scaling notch3 dsp double notch filter at 800 Hz and 2400 Hz canonical form Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 D
4. dm tx_buf 1 mri dm tx_buf 2 mri left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The time varying delay is generated by a sinusoidal wavetable A special feature of this implementation is that we cannot call tap directly to get the d th tap because the value of d is passed through a data register and the instruction set will not allow us to negate it Thus we replace tap by its individual instructions and take the negative with the help of the ALU register ar Lab Procedure a Go to directory c adi_dsp examples flanger Compile and run this pro gram Then repeat by lowering the frequency of the varying delay to 2 Hz b Repeat with increasing the maximum delay to 300 msec c Repeat parts a b by replacing the sinusoidal wavetable with a square wave one Phasers The following program phaser dsp implements a phaser as a variable notch filter phaser dsp phasing effect with a variable notch filter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Section 8 2 2 and Eq 8 2 22 if Introd to Signal Processing Design width Df 80 Hz bO 1 1 tan Dw 2 0 9695 Notch frequency varies sinusoidally from 200 Hz to 800 Hz fO 500 300 sin 2 pi fsweep t wO 0 125 pi 0 075 pi sin 2 pi fsweep t Cin Hz
5. 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 4 EXPERIMENTS 77 include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const AO 0x4000 A0 0 5 input scale factor filter order circular delay line buffer in DM concatenated coeffs in PM const M 2 var dm circ w M 1 var pm circ a M 1 b M 1 const ea 1 scaling exponent for a const eb 1 scaling exponent for b const ex 4 input scaling exponent i2 Aw L2 w delay line buffer pointer and length 14 Aa L4 2 M 1 double length a b coefficients zero i2 m2 L2 clear delay line wavetable s min freq fs Ds 10 Hz square wavetable const Ds 800 var dm circ s Ds 16 As L6 s wavetable pointer and length square wave frequency f1 c fs Ds A A0 4 square wave amplitude const c 80 Cconst A 0x1000 load wavetable denominator coefficients numerator coefficients init s lt squartbl hex gt init a lt a hex gt init b lt b hex gt start processing input samples
6. ar dm i5 m5 get sampling pulse ar pass ar forces updating of AZ flag if ne jump output if AR 0 write output mrO 0 felse write zero outputs mr1 0 write output samples to codec output if 1 optional amplification sr ashift mrO by 1 Chi mrO srl sr ashift mr1 by 1 hi mri srl endif dm tx_buf 1 mrO left output sample dm tx_buf 2 mrl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The re sampling operation is accomplished by multiplying the input samples x n at the initial rate fs by a periodic re sampling pulse train s n consisting of unit impulses every M of the original samples and has zeros otherwise that is s n 1 0 0 0 1 0 0 0 1 0 0 0 qx mm AAA M 1 M 1 M 1 The re sampled input signal will be x n s n x n It is nonzero only every M samples These nonzero samples are separated by a sampling time interval T MT resulting in the reduced sampling rate A od 1 1 fs Va P ur Me If M becomes too large aliasing effects will become audible as the spectral im ages due to sampling overlap more and more The aliasing will arise from the spec tral components of x n that lie outside the reduced Nyquist interval f 2 f 2 A more mathematical discuss
7. axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm for left channel mr 0 mrl axl mr x left input myO aL tap i2 m2 DL mx0 mr mr mxO myO rnd mx0 sD D th tap mr sO x a sD tapin i2 m2 mr1 cdelay i2 m2 put sO in tap O update left delay mr mri my0 rnd mr a sO 4 EXPERIMENTS 44 ay0 mx0 fay0 sD ar ay0 mri ar y sD a sO dm tx_buf 1 ar write left output to codec sample processing algorithm for right channel mr 0 mr1 mx1 mr x right input myO aR tap i3 m3 DR mx0 mr mr mx0 my0 rnd mx0 sD D th tap mr sO x a sD tapin i3 m3 mrl cdelay i3 m3 put sO in tap 0 update right delay mr mri myO rnd mr a sO ayO mx0 ay0 sD ar ay0 mri ar y sD a sO dm tx_buf 2 ar write right output to codec return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup Although the overall frequency response of the allpass reverberator is unity the intermediate stage of computing the recursive part S can overflow because this part is just like the plain reverb and its peak gain is 1 1 a The allpass reverberator can also be im
8. 200 Hz 200 Hz 800 Hz 3 800 Hz 0 5 fie i E fh i S N A S osoHfi E okt n ail a i i 0 00 1 0 0 0 04 08 12 16 20 24 28 32 36 40 00 04 08 12 16 20 24 28 32 36 4 0 f kHz f kHz As Wo Varies these two filters continuously morph into each other In the program the filter is implemented in its direct form to avoid overflows Moreover because the middle coefficients a b 1 9390cos wo take on values in the 2 14 format s range we have used that format to convert them to hex This ef fectively divides the filter coefficients by 2 and must be compensated by using the scaling exponents g ep 1 corresponding to the scaling factors Gg 2 2 Gp 2 2 The varying notch frequency is generated using a sinusoidal wavetable Because Wo remains small we have calculated cos Wo using the approximation 1 cosx 1 x 2 Lab Procedure a Compile and run the program phaser dsp Experiment with lower and higher values of the sweep frequency b Repeat part a using a square wavetable c Write another version of the program that calculates cos Wo using the im proved approximation 1 1 cosx 1 x xt 2 24 Then let the notch frequency vary over a somewhat wider range 4 17 Simulator Examples The first two simulator examples simulate the quantization and downsampling al gorithms discussed in Section 4 1 of this manual Qu
9. k d delays gt y for each input x do x Si 3 E z y tap D w p d Lal z Lal zZ P o a Zz gt Lal Z gt ES So Sy Sy Sa Sp p X l D delays gt cdelay D w amp p General FIR Filter Program The implementation of an FIR filter is accomplished with the help of the macro cfir which is the assembly code equivalent of the text routines cfir c and cfir2 c The following is a general FIR filtering program fir dsp FIR filter experiment Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on cfir c or cfir2 c of Introduction to Signal Processing define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 4 EXPERIMENTS 26 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 nanan nena nnn nnn nnn nnn enn nnn nnn nnn include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const M 206 var dm circ w M 1 var pm circ h M 1 from firlp m with fc 200 Hz Df 100 Hz circular delay line buffer in DM filter coefficient buffer in PM i2 Aw L2 w delay line buffer pointer and length i4 Ah L4 h coefficient buffer
10. DD x 50 gt it yy for each input x do z xp S9 X s Mo S tap 3 w p 1 ae 3 S2 tap 3 w p 2 ie 3 tap 3 w p 3 3 O 2 y 280 3S1 252 83 i z cdelay 3 w amp p 3 Since the range of the filter coefficients is 4 4 we must convert them with the 3 13 format resulting in the hex numbers h 2 3 2 1 0x4000 0xa000 Oxc000 0x2000 Equivalently these are the filter coefficients scaled down by 4 in order to fit within the 1 15 format namely 1 race 3 2 1 0 50 0 75 0 50 0 25 0x4000 Oxa000 Oxc000 0x2000 Because the MAC performs its multiplications in the 1 15 format after the final output y is computed it can optionally be scaled up by a factor of 4 with the help of the shifter The following instructions declare the delay and filter coefficient circular buffers and initialize them filter order delay line buffer placed in DM filter coefficient buffer placed in PM const M 3 var dm circ w M 1 var pm circ h M 1 init h 0x4000 Oxa000 Oxc000 0x2000 coefficient values 12 14 Aw L2 Ah L4 w delay line buffer pointer and length h coefficient buffer pointer and length nol zero i2 m2 L2 clear delay line buffer to zero Assuming as in the previous example that the codec inputs and outputs come from receive and transmit buffers in DM the sample processing algorithm can be trans lated
11. h 1 0 0 0 a 0 0 0 a7 0 0 0 a ee D 1 zeros D 1 zeros D 1 zeros Because of the sparseness of the impulse response a more efficient implementation is to program the block diagram directly in the sense of using a common delay line of order 3D and tapping it out at taps 0 D 2D and 3D The block diagram realization and corresponding sample processing algorithm will be 4 EXPERIMENTS 33 Xx 5 AN gt y 20 D for each input x do E a So X s tap 3D w p D S2 tap 3D w p 2D z g 3 tap 3D w p 3D Sy as y So aS a S a383 Y D So D Zz a cdelay 3D w amp p 3 gt The following program comb dsp is the translation to assembly language comb dsp FIR comb filter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Eq 8 2 8 of Introduction to Signal Processing I O equation y n a0 x n al x n D a2 x n 2D a3 x n 3D Sample processing algorithm for each x do p 50 x read filter input sl tap 3 D w p D get tap D s2 tap 3 D w p 2 D get tap 2D s3 tap 3 D w p 3 D get tap 3D y a0 sO al s1 a2 s2 a3 s3 filter output cdelay 3 D w amp p update delay define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9
12. tap s1 into sr0 tap s2 into srl my0 b0 mr mx1 my0 ss mr bO x my0 b1 mr mr srO my0 ss mr bO x b1 s1 my0 b2 mr mr srl my0 rnd mr y bO x b1 s1 b2 s2 if mv sat mr write output samples to codec dm tx_buf 1 mrl left output sample dm tx_buf 2 mrl right output sample sample processing algorithm cont d mr 0 mrl mx1 mr x my0 al mr mr srO my0 ss mr x al s1 my0 a2 mr mr srl my0 rnd mr sO x al s1 a2 s2 if mv sat mr tapin i2 m2 mr1 input sO into delay cdelay i2 m2 update delay 4 EXPERIMENTS 62 return from interrupt pois include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Go to the directory c adi_dsp examples multitap Compile and run this program Listen to its impulse response and speak into the mike b Repeat for the following values of the feedback parameters a a 0 5 which makes the system marginally stable with a periodic steady output any random noise would be grow unstable Repeat also for the case a a2 0 75 which corresponds to an unstable filter Please reset the processor before the output grows too loud 4 13 Karplus Strong String Algorithm A model of a plucked string is o
13. 8000 800 10 Hz at an 8 kHz sampling rate We took A 1 for the amplitude and generated the D sinusoidal values by the DOS wavetable generator sinetbl exe and converted them to hex by the DOS commands sinetb1 0 1 800 gt sinetbl dec dec2hex 1 15 lt sinetbl dec gt sinetbl hex The wavetable is loaded on the chip at run time The wavetable is cycled over at different speeds by two independent DAG2 pointers 15 and 16 which are incre mented respectively by m5 c1 and m6 c2 The wavetable increments are c 10 and C2 40 resulting in the frequencies f 100 and fz 400 Hz One is in the passband and the other in the stopband of the filter Thus the filter will remove f2 and let f pass through The amplitudes were chosen to be A 42 0 5 In Section 4 14 we discuss the definition and use of the macro wavgen dsp which can also be used to generate the required sinusoids Lab Procedure a Go into the directory c adi_dsp examples fir Then convert the filter coefficient file 1p1 dec into the hex file fir hex Then compile and load the fir dsp program These operations are carried out by the commands dsp cd fir dec2hex 1 15 lt lp1 dec gt fir hex ezk fir ezl fir 4 EXPERIMENTS 32 Speak into the mike or sing a do re mi scale Note how the filter cuts off the higher pitches of your voice b Next test the longer filter First edit the file fir dsp so that M 2054 then convert the coefficient file 1p2 dec into
14. delay line buffer delay line buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 mx1 dm rx_buf 2 left input sample right input sample sample processing algorithm process right channel only mr 0 tap i2 m2 D mri mr sD D th tap my1 a mr mr mx1 my1 rnd mr y sD a x srl mri srl y mr 0 mrl mx1 mr x mr mr srl my1 rnd mr sO x a y tapin i2 m2 mri cdelay i2 m2 put sO in tap 0 update delay write output samples to codec dm tx_buf 1 srl dm tx_buf 2 srl left output sample right output sample 4 EXPERIMENTS 46 return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Go to directory c adi_dsp examples allpass compile link and run the program allpass dsp with the parameter values D 3000 and a 0 5 Repeat with a 0 9 Listen to the impulse response of the system Speak into the mike Compare the ou
15. fs Ds const A 0x1000 A A0 4 square wave amplitude init s lt squartbl hex gt load wavetable init a lt al3 hex gt denominator coefficients init b lt b13 hex gt numerator coefficients start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm wavgen i6 m6 A c mr mr1 A square wave myl AO mr mr mx1 my1 rnd mr x AO mike A square if mv sat mr srl mr1 jump nofilter uncomment to bypass filter sr ashift mr1 by ex hi pre scale x down compute output y ccan M 14 m4 12 m2 ea eb sri input from srl output in srl sr ashift srl by ex hi post scale y up write samples to codec nofilter dm tx_buf 1 srl left output sample dm tx_buf 2 srl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Run the program notch1 dsp with the filter off Then run it w
16. typical usage cdir M 14 m4 12 m2 13 m3 ea eb axl 5 MACROS internal operation tapin i3 m3 ax1 mr 0 tapin i2 m2 mr1 dot M 14 m4 i2 m2 sr ashift mr1 by ea hi ayl srl dot M 14 m4 13 m3 sr ashift mr1 by eb hi ar srl ayl tapin i2 m2 ar cdelay i2 m2 cdelay i3 m3 106 u0 x input sO 0 dot M a s Ga dot M a s dot M b u Gb dot M b u output y in AR s0 y update y delay update x delay macro cdir 0 1 2 3 4 5 6 7 8 9 tapin 5 6 9 mr 0 tapin 3 4 mr1 dot 0 1 2 3 4 sr ashift mr1 by 7 hi ayl srl dot 0 1 2 5 6 sr ashift mr1 by 8 hi ar srl ayl tapin 3 4 ar cdelay 3 4 cdelay 5 6 endmacro The coefficients must be scaled in the same way as in the canonical form Fig 5 2 shows the scaled realization 1 G G l MGs re WA E van Ga A y Uy Y ry i A So Z ge pif Zz bf a 1 NA u yt IN y 51 1 1 Z d z bs dy 2 Uy gt lt 1 Sy Fig 5 2 Direct form with scaling factors The sample processing algorithm is the circular version of that in Eq 7 1 10 of the text and can be stated in the following form that uses the scaled coefficients again the input prescaling is not implemented inside cdir 5 MACROS 107 for each input sample x do
17. 1 0 980741z 0 961111z 2 0 942964z 3 0 924447z 4 The magnitude responses of the two single notch filters H z H3 z and of the double notch filter H 3 Z are shown below H z A3 Z H z Single Notch Filters Double Notch Filter gt 1 0 ee N 7 H3 ji 0 5 Ae 2 4 3 2 4 0 80 0 8 1 6 2 4 3 2 4 0 kHz f kHz 0 0 0 0 0 8 1 0 4 EXPERIMENTS 75 The program notch1 dsp implements the filter H Z in its direct form using the macro cdir The coefficients must be scaled down by a factor of 2 to make them fit into the 1 15 format Thus we must use scaling exponents eg ep 1 notchl dsp single notch filter at 800 Hz amp width 50 Hz direct form Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Designed with parmeq m of Appendix D with the MATLAB commands GB 1 sqrt 2 fO 800 fs 8000 Df 50 b a beta parmeq 1 0 GB 2 pi f0 fs 2 pi Df fs define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 oo include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buff
18. 1 4 0 25 1 4 y 0 0626 1 16 0 1875 3 16 0 1875 3 16 0 3125 5 16 0 1875 3 16 0 4375 7 16 0 2500 4 16 0 1875 3 16 0 1875 3 16 0 0000 0 16 0 0625 1 16 The h coefficients and x have been scaled down to fit in 1 15 format as compared to Example 4 2 1 include lt c adi_dsp macros dspmac dsp gt module ram abs 0 firex2 const L 8 const M 3 var dm ram x L var dm ram y L M var dm ram circ w M 1 var pm ram circ h M 1 init x lt xfir hex gt init h lt h hex gt jump start nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop start 12 Aw L2 w 14 h L4 h 13 Ax m3 1 L3 i5 Ay m5 1 L5 dsp macros input signal length filter order input samples output samples delay line buffer in DM filter taps in PM read L input samples read M 1 filter taps Interupt vector table No interrupts used delay line buffer filter taps buffer input samples output samples 4 EXPERIMENTS zero i2 m2 L2 cntr L do outputs until ce ax0 dm i3 m3 cfir M 14 m4 12 m2 ax0 outputs dmC i5 m5 mri cntr M do transients until ce ax0 0 cfir M 14 m4 12 m2 ax0 transients dm i5 m5 mri idle endmod TIR Filter Examples 93 clear delay line process L input samples r
19. 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 typical usage Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 cdelay i2 m2 Oxc85e 9 6 Oxc85f 6 615 tap i2 m2 d my1 Peis A O eee eee eee tapin i2 m2 mx1 dot M 14 m4 i2 m2 include lt c adi_dsp macros begin dsp gt initializations and DSP macros cfir M 14 m4 i2 m2 mx1 ccan M 14 m4 12 m2 ea eb axl define constants variables and buffers cdir M 14 m4 12 m2 13 m3 ea eb axl A tet siesecs example wavgen i5 m5 A c my1 const D 7670 approximately max delay for EZ KIT Lite zero i2 m2 L2 var dm circ w D 1 circular delay line buffer of length D 1 i2 Aw L2 w delay line buffer pointer and length include lt c adi_dsp macros cdelay dsp gt include lt c adi_dsp macros tap dsp gt zero i2 m2 L2 initialize delay line to zero include lt c adi_dsp macros tapin dsp gt ioe A ee oes one ek ee O A fe ee include lt c adi_dsp macros dot dsp gt include lt c adi_dsp macros cfir dsp gt start processing input samples include lt c adi_dsp macros ccan dsp gt include lt c adi_dsp macros cdir dsp gt wait idle jump wait wait for interrupt and loop forever include lt c adi_dsp macros wavgen dsp gt interru
20. 3 three input off transients m2 3 modify i2 m2 point back to tap 0 do transients until ce my1 dm w 3 get tap 3 dm i5 m5 myl write y dmci5 m5 myl save in y and point to next y mx1 dm i3 m3 get input x mx0 0 m2 0 dm i2 m2 mx1 put it into tap 0 dm w mx0 put 0 in delay line 4 EXPERIMENTS 90 m2 1 outputs modify i2 m2 backshift buffer pointer cntr 3 3 input off transients do transients until ce m2 3 modify i2 m2 m2 0 my1 dm i2 m2 m2 3 modify i2 m2 point to tap 3 get tap 3 point back to tap 0 dmci5 m5 myl write y mx1 0 m2 0 dm i2 m2 mx1 zero input x put it into tap 0 m2 1 transients modify i2 m2 backshift buffer pointer idle endmod FIR Filter Examples The next two examples illustrate FIR filtering and are based on Example 4 2 1 of the text 1 The input signal and filter are Bo x 1 1 2 1 2 2 1 1 4 aja The output is the convolution 1 y hxx 1611 3 3 5 3 7 4 3 3 0 1 In 1 15 format the filter input and output signals are h x 0x2000 0x4000 Oxe000 0x2000 0x2000 0x2000 0x4000 0x2000 0x4000 0x4000 0x2000 0x2000 0x0800 0x1800 0x1800 0x2800 0x1800 0x3800 0x2000 0x1800 0x1800 0x0000 0x0800 The filter and input hex numbers can also be obtained by converting the unscaled signals in the 3 13 format The output samples can be converted u
21. 4 12 Multitap Delay Effects mx1 dm rx_buf 2 right input sample This experiment is based on the multi tap delay line effects processor of Fig 8 2 29 sample processing algorithm process right channel only of the text 1 It uses a common circular delay line buffer of order D D2 which is tapped out at taps D and D D2 The sample processing algorithm is tap i2 m2 D1 sr0 sr0 s1D D1 th tap tap i3 m3 D2 sri srl s2D D2 th tap my0 b0 mr mx1 my0 ss mr bO x my0 b1 4 EXPERIMENTS 60 l b 0 Y a So X gt y Y i zP 1 i a i b gt a 2 b for each input sample x do s tap D D2 w p D1 So tap D D2 w p D Do y box b s b252 So X 41581 0282 p So cdelay D D2 w amp p The following program multitap dsp is an assembly language implementation multitap dsp multitap delay line with feedforward and feedback Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Fig 8 2 29 of Introduction to Signal Processing The sample processing algorithm is for each x do sl tap D1 D2 w p D1 s2 tap D1 D2 w p D1 D2 D1 th tap output D1 D2 th tap output y bO x b1 s1 b2 s2 filter output p s0 x al s1 a2 s2 put input sO into delay cdelay D1 D2 w amp p update delay define
22. and 32 bit formats and their variants such as the 2 6 3 21 or 2 30 formats 2 3 Wavetable Generator Programs The DOS programs sinetbl exe squartbl exe trapztbl exe are wavetable generators generating one period of sinusoidal square wave and trapezoidal wave forms Their C source code is included in the Appendix Just typing the name of any of these utilities on the DOS command line followed by lt RET gt will display their usage These programs can be used in conjunction with the wavgen dsp macro to generate waveforms of different frequencies Some examples of their usage are as follows 3 INSTRUCTION SET TUTORIAL 5 sinetbl1 O 1 2000 gt sin dec sinetb1 1 1 2000 gt cos dec squartb1 1 1 1000 2000 1 gt squarel dec squartb 1 1 1000 2000 0 gt square2 dec The first generates one period of length 2000 samples of a unit amplitude sinusoid and the second a period of a cosinusoid that is 27M 0 1 D 1 D n 0 1 X1 n sin 557 X 2 n cos with D 2000 The third and fourth examples generate one period of the square waves x3 n 1 1 1 1 1 1 Sn 1000 ones 1000 minus ones x4 n 0 1 1 1 0 1 1 1 999 ones 999 minus ones The square wave x n jumps discontinuously from level 1 to 1 whereas x4 n has the value 0 at the discontinuities See Section 4 15 for more on this 2 4 Subdirectory Structure The default installation directory of the EZ KIT Lite software
23. ay bx So nT lt cdelay D w amp p 1 a A quick way to understand this transposed realization is to write Y z l z X z l1 az H z from where we obtain the I O equation on which the block diagram is based Y z bX z zP aY z bX z In the experiment we take the fundamental period to be 800 Hz and the sam pling rate 8 kHz Thus the period D is fs _ 8000 Hz fi 800 Hz The width of the notches is taken to be Af 50 Hz Then the design equations 8 3 27 give the parameter values b 0 91035 a 0 8207 Their 1 15 hex equiv alents are 0x7486 and 0x690d respectively The magnitude response of this filter plotted over the right half of the Nyquist interval is shown below together with a magnified view of the notch width at 800 Hz Notching Comb Filter D 10 Notch Width Af 50 Hz Ge VU Ge Ga T ff H A 0 0 i i i y i i 24 3 2 4 0 0 700 0 725 0 750 0 775 0 800 0 825 0 850 0 875 0 900 f kHz f kHz Using a square wavetable the program notch dsp generates a square wave of period D 10 and adds it to the microphone input The resulting signal is then filtered by the above multi notch filter removing the periodic noise 4 EXPERIMENTS 71 notch dsp notching comb filter canceling 800 Hz harmonics Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Eq 8 3 26 and Example 8 3 9 of Introd to Signal Proce
24. const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a0 Ox7fff a0 0 9999 approximate unity const al 0x4000 al 0 50 const a2 0x2000 a2 alA2 0 5042 0 25 const a3 0x1000 a3 a143 0 5043 0 125 const D 2000 TD D fs 2000 8000 1 4 sec var dm circ w 3 D 1 delay line buffer max delay 3 D delay line buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples 4 EXPERIMENTS 34 4 EXPERIMENTS 35 Listen to the impulse response of the filter Speak into the mike Bring the wait idle jump wait wait for interrupt and loop forever mike close to the speakers and get a closed loop feedback interrupt service routine starts here input_samples ena sec_reg enable secondary register set b Keeping the delay D the same choose a 0 2 and run the program again What effect do you hear Repeat for a 0 1 read input samples from codec axl dm rx_buf 1 left input sample c Finally run the program with the values a 1 and a 1 Note that 1 is
25. fetches s3 h3 and wraps around to point to the beginning of the circular buffers namely to Sy Ay The next line performs the final accumulation mr hoso hs hos2 h3s3 and rounds the result to its 16 most significant bits contained now in mr1 The result is saturated if overflow is detected Then the delay line is updated by backshifting its pointer 12 Note that the argument m2 of cdelay i2 m2 is set internally to m2 1 in the macro Then the computed output in mr1 is scaled up by a factor of 4 by the shifter and the scaled result is placed in sr1 and finally sent out to the codec The repeated multifunction instructions can be replaced by a do loop which ef fectively performs the dot product of the internal states with the filter coefficients m2 1 m4 1 mr 0 mxO dm i2 m2 my0 pm i4 m4 cntr M M filter order do dotloop until ce dotloop mr mr mxO myO ss mxO dm i2 m2 myO pm i4 m4 mr mr mxO myO rnd if mv sat mr These instructions have been collected into a macro dot dsp with usage dot M 14 m4 12 m2 result returned in mr1 Fig 3 6 illustrates the dot product operation Note that 14 pointing to the filter coefficients cycles back to the beginning of the buffer and 12 pointing to the filter states cycles back to the Oth state In summary the sample processing algorithm can be simplified to the three operations of a reading the input sample into the del
26. mrl left output sample which requires a 4D 1 dimensional delay line buffer The canonical real dm tx_buf 2 mri right output sample ization and the corresponding sample processing algorithm are shown below return from interrupt ETS z es x sof z y for each input x do dl D i s tap 4D w p D include lt c adi_dsp macros end dsp gt wrapup Sa tap 4D w p 4D lt Sj So X as The delay D is taken to be D 2000 corresponding to Tp 0 25 sec so that a ET Y So 04 S4 the total duration of the filter is 3Tp 0 75 sec The parameter a is chosen to be z at xp So a 0 5 S4 cdelay 4D w amp p Lab Procedure The following program comb2 dsp is the assembly code implementation Us ing the values D 1600 corresponding to a 0 2 sec delay and a 0 5 recompile and run both the comb dsp and comb2 dsp programs and listen to their outputs In general such recursive implementations of FIR filters are deb more prone to the accumulation of roundoff errors than the non recursive cd comb versions You may want to run these programs with a 1 and a 1 to ezk comb observe this sensitivity ezl comb a Go to directory c adi_dsp examples comb compile link and load the pro gram using the commands 4 EXPERIMENTS 36 comb2 dsp FIR comb filter implemented recursively Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based o
27. mxi jump nofilter uncomment to bypass filter sr ashift srl by ex hi pre scale x down compute output y input from sri output in ar post scale y up make it a little louder cdir 2 14 m4 12 m2 13 m3 ea eb srl sr ashift ar by ex hi sr ashift srl by 1 Chi write samples to codec nofilter dm tx_buf 1 srl left output sample dm tx_buf 2 srl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The notch frequency varies sinusoidally between the limits of 200 Hz and 800 Hz fo 500 300 sin 27tfsweept where the sweep frequency is initially chosen to be sweep 10 Hz Assuming an 8 kHz sampling rate the notch frequency in radians per sample will be Wo 0 12571 0 07577 sin 2Ttf sweep The filter s transfer function is given by Eq 8 2 22 of the text 1 The width parameter b 0 9695 was calculated from Eq 8 2 23 by assuming a 3 dB width of Af 80 Hz or Aw 0 02Tr The filter s transfer function is therefore 0 9695 1 9390 cos wo z 0 9695z 1 1 9390 cos Wo z 0 9390z 2 H z The magnitude and phase responses of the two filters corresponding to the two extreme values of the notch frequency fo 200 800 Hz are shown below 4 EXPERIMENTS 85 Notch Filters Phase Responses
28. myO dm i5 m5 mr mxO my0 rnd 6 APPENDIX 108 my1 mrl macro wavgen 0 1 2 3 4 1 3 mx0 2 myO dm 0 1 mr mx0 my0 rnd 4 mrl endmacro 6 Appendix This appendix contains the listings of the following files all of which reside in the directory c adi_dsp macros dec2hex c hex2dec c sinetb1 c squartb1l c trapztbl c uran c template dsp dspmac dsp 6 1 Decimal to Hex Format Converters The decimal to hex format converter dec2hex c uses the adc c routine of the text 1 to get the 2 s complement binary representation of a number and then it collects the bits in groups of fours to get the hex digits It can be used with any value of B such as B 8 16 24 32 as long as a and b are such that a b B dec2hex c decimal to hex a b format converter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Usage dec2hex a b lt decimal dat gt hex dat include lt stdio h gt include lt math h gt include lt stdlib h gt include lt string h gt void adc 2 s complement ADC with rounding from 12SP ch 2 void main int argc char argv int i a B b h double x R b bit vector h hex vector if argc 2 puts nDecimal to hex a b format converter puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n puts Usage dec2hex a b lt decimal dat gt hex dat puts e g dec2hex 1
29. sD a v1 if mv sat mr srO mri save vO for later updating v1 my0 b0 mr mr1 my0 ss mr bO vO mx0 b1 mr mr mxO my1 rnd mr u bO vO b1 v1 if mv sat mr ayl mx1 ayl x input ar mrl ayl far y Xx u output dm v1 sr0 update lowpass filter v1 vO tapin i2 m2 ar put y in tap 0 cdelay i2 m2 update delay write output samples to codec 4 EXPERIMENTS 64 dm tx_buf 1 ar dm tx_buf 2 ar left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup In this experiment the sampling rate is set to 44 1 kHz and the generated sound is the note A440 that is having frequency 440 Hz The correct amount of delay is then fs 44100 D 100 fi 440 The delay line must be filled with D 1 random numbers They were generated as follows by the routine uran c given in the Appendix uran 0 1 100 2001 dec2hex 1 15 gt w440hz hex where the seed value was arbitrary and the output of uran was piped into dec2hex whose output was the hex file w440hz hex Similarly the file w220hz hex contains twice as many random numbers which are used to generate the frequency 220 Hz Lab Procedure a Go to the directory c adi_dsp examples guitar Set D 100 in the pro gram copy w440hz hex
30. sample processing algorithm wavgen i6 m6 A c mr1 mr1 A square wave myl AO mr mr mx1 my1 rnd if mv sat mr srl mr1 jump nofilter uncomment to bypass filter sr ashift mr1 by ex hi pre scale x down compute output y input from sri output in ar post scale y up cdir M 14 m4 12 m2 13 m3 ea eb srl sr ashift ar by ex hi write samples to codec nofilter dm tx_buf 1 srl left output sample dm tx_buf 2 srl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup 76 mr x AO mike A square The program notch2 dsp implements the filter H z in its canonical form using the macro ccan To prevent overflows the input signal must be scaled down by a factor of 16 2 before it is passed to the filter and the output scaled up by the same factor Thus the input scaling exponent is ex 4 notch2 dsp single notch filter at 800 Hz amp width 50 Hz canonical form Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Designed with parmeq m of Appendix D with the MATLAB commands GB 1 sqrt 2 fO 800 fs 8000 Df 50 b a beta parmeq 1 0 GB 2 pi f0 fs 2 pi Df fs define sampling rate in kHz
31. the direct sound path has been removed c 0 in order to let the echoes be more 4 EXPERIMENTS 57 clearly heard b What values of b and c would you use expressed in terms of a in order to implement a plain reverberator of the form 1 H z 1 az For a 0 5 calculate the proper values of b c and then compile and run the program Compare its output with that of plain dsp c Compile and run the cases a 1 b c 1 anda 1 b 1 c 1 What are the transfer functions in these cases 4 11 Multi Delay Effects Here we consider the multi delay effects processor shown in Fig 8 2 27 of the text 1 We assume that the feedback filters are plain multipliers Using two sepa rate circular buffers for the two delays the block diagram realization and sample processing algorithm are in this case x 10 R gt i ae A gt ZP1 as I A a s by Oe eg yU y fai gt L for each input x do Sip tap D1 W1 P D1 Sop tap D2 W2 p2 D2 y box biSip b2 2D P2 S20 S1D 0282D cdelay D2 W2 amp p2 P1 S10 X 0181D cdelay D1 wi amp p1 The program multidel dsp is an implementation multidel dsp multi delay effects algorithm Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Fig 8 2 27 of Introduction to Signal Processing Assuming the feedback filters are plai
32. variable multi notch filters or even lowpass filters with continu ously variable cutoff frequency Flangers The program flanger dsp implements a simple flanging processor as defined by Eqs 8 2 17 and 8 2 18 of the text 1 The delay varies sinusoidally from 0 to 50 msec with a frequency of 4 Hz For simplicity we do not use a linearly interpolated delay flanger dsp flanging processor Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Eqs 8 2 18 8 2 19 of Introduction to Signal Processing I O equation y n 0 5 x n 0 5 x n d n Sample processing algorithm for each x do p sO x d D D sin 2 pi fc t 2 sl tap D w p d y a0 s0 al s1 cdelay D w amp p variable delay define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 4 EXPERIMENTS 81 Oxc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a0 0x4000 a0 0 50 const al 0x4000 al 0 50 const D 400 TD D fs 400 8000 50 msec var dm circ w D 1 const D2 D 2 delay line buffer ma
33. 3 4 4 4 5 4 6 4 7 4 8 4 9 Sampling and Quantization o o Delays Dina e a RT A a er ee A oe ee FIR Filters 3 ciate tee de ee ee E Comb Filters o ur aia a Boe A a ee eo aed Plain Reverb nr e a aoea eo OR eke ed ea we wh ea aw a Allpass ReVerD a aa a tou e hook eRe Beco E E ae ee a Lowpass ReveTb lt a Schroeder s Reverb o oo Stereo Reverb ice dr a we E Ga a a ee ae e E 4 10 Reverberating Delay oo e eee 4 11 Multi Delay Effects o o e ee 4 12 Multitap Delay Effects o oo ee 4 13 Karplus Strong String Algorithm 00 4 14 Wavetable Generators o 4 15 NOtCh Filters ua a A a da ee a 4 16 Flangers and PhaserS o e e 4 17 Simulator Examples lt saa seo oreda dada dae aea ee Macros 5 1 5 2 5 3 5 4 5 5 5 6 CONTENTS 3 5 7 CCAM aa a is Td Em das de actas bos da 102 SOC ia a de E dabas Oa ai ee RA 105 A E RN aes E 107 6 Appendix 108 6 1 Decimal to Hex Format Converters n o o oaos aoao 108 6 2 Wavetable Generators 2 ooa oao e a es 110 6 3 Template and Begin End Files aaao a 113 References 115 1 INTRODUCTION 1 1 Introduction This manual describes a number of hardware experiments illustrating the concrete implementation of various DSP algorithms on the ADSP 2181 chip The experiments include quantization and
34. 3 4 Writing into tap 0 of a circular delay line buffer 3 INSTRUCTION SET TUTORIAL 12 3 6 Updating a Delay Once the input to the delay line buffer is in we may update the delay by simply backshifting the pointer 12 m2 1 modify i2 m2 Fig 3 5 illustrates this operation These two instructions have been placed into the macro cdelay dsp with usage cdelay i2 m2 In summary the following macros in the directory c adi_dsp macros facilitate the operations required in circular delay lines zero i2 m2 L2 tapin i2 m2 mx1 tap i2 m2 d mr1 cdelay i2 m2 clear delay line to zero put mx1 into tap 0 of delay line get the d th tap and put in mr1 update delay line DM DM Wo Wo j 2 1 MES new Tp circular DAGI a T 2 Sy buffer 1 10 mo LO le il mi L1 vt ma i2 m2 L2 p i3 m3 L3 before updating after updating Fig 3 5 Updating a circular delay line buffer 3 7 Multifunction Instructions and FIR Filters Using the above circular buffer tools we present a final example on implementing an order 3 FIR filter and we also discuss multifunction type instructions The I O equation is y n 2x n 3x n 1 2x n 2 x n 3 The block diagram and circular buffer version of its sample processing algorithm are shown below 3 INSTRUCTION SET TUTORIAL 13
35. B format x b 27 b227 b323 bp2 F 24 a b format where a 0 1 B Alternatively we may think of the a b format as the scaled down version of the B 0 two s complement integer format Writing a B b in the above expressions we have x b 28 1 b228 2 b328 3 bp B 0 format x b 23 1 b gt 2B 24 b3283 bg 2 a b format where b 0 1 B Fig 2 1 shows the bit weighting factors and the placement of the fractional point for the four formats 0 16 1 15 2 14 and 3 13 0 16 b b b b bs be b bg by bip bii biz bis bia bis bis 001 02 3 4 2 5 6 7 8 9 10 11 12 13 14 _ 15 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 15 b b bz b b b b bg bo bio Pi biz bis big bis bis 1 0 1 2 3 4 5 6 7 8 9 _ 10 _ 11 _ 12 _ 13 _ 14 2 2 2 X 2 A 2 2 2 2 2 2 2 2 2 2 2 14 b b bz b bs b b7 bg bo Pio br by biz bis bis bis 2 1 0 1 2 3 4 5 6 7 8B _ 9 10 _ 11 _ 12 13 2 2 2 2 2 2 2 2 2 2 2 2 2o 2o 2 2 3 13 b by b3 by bs b b bg by bi bi by bj by bis by Fig 2 1 Bit weights for 0 16 1 15 2 14 and 3 13 formats The programs dec2hex and hex2dec can be applied to any B which is a multiple of 4 For example they can convert to from the 1 7 1 23 or 1 31 formats which are 8 bit 24 bit
36. Hz Df 50 Hz start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec 4 EXPERIMENTS 72 axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm wavgen i6 m6 A c mr1 mr1 A square wave my1 AO mr mr mx1 my1 rnd mr x AO mike A square if mv sat mr far mr1 jump nofilter uncomment to bypass filter mx1 mri save x temporarily my0 b mr mx1 my0 rnd mr1 b x if mv sat mr tap i2 m2 D ay1 ay1 sD D th tap ar mr1 ayl ar y b x sD output my1 a mr ar myl ss mr a y my1 b mr mr mx1 my1 rnd mr sO a y b x if mv sat mr tapin i2 m2 mr1 put sO into tap 0 cdelay i2 m2 update delay line write samples to codec nofilter dm tx_buf 1 ar left output sample dm tx_buf 2 ar right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The filtering operation can be bypassed by uncommenting the jump nofilte
37. Its transfer function is H 2 c b3 7D zP Its block diagram realization and corresponding sample processing algorithm using a circular delay line buffer are given below X gt gt z Sp Wa for each input x do Sp tap D w p D ry Y CX SpD Nu xp Sy bx asp cdelay D w amp p The following program revdel dsp is an implementation revdel dsp reverberating delay with Junior DSP Lab Rutgers ECE Dept S Based on Problem 8 17 of Introduction Sample processing algorithm for each input x do sD tap D w p D y sD C x sO b x a sD p s0 cdelay D w amp p define sampling rate in kHz 0xc850 0xc853 11 025 const fs 0xc850 0xc856 32 Oxc85b 44 1 Oxc85e 9 6 l co include lt c adi_dsp macros begin dsp gt direct path J Orfanidis Jan 1996 to Signal Processing D th tap output of delay c direct path gain y output b gain before delay put sO into delay s tap 0 update delay Oxc851 5 5125 Oxc852 16 Oxc854 27 42857 Oxc855 18 9 Oxc857 22 05 Oxc859 37 8 Oxc85c 48 Oxc85d 33 075 Oxc85f 6 615 initializations and DSP macros define constants variables and buffers 4 EXPERIMENTS 56 const a 0x4000 a 0 5 feedback gain Cconst b Ox7fff b 0 9999 gain before delay const c 0x0000 c 0 gain f
38. Section 8 1 3 of Ref 1 and also in Section 4 14 of this manual and in the Appendix The wavetable stores one period of length D samples of a sinusoid and it is stepped at increments of every c samples The resulting sinusoid will have frequency f cfs D dnsamp2 dsp aliasing of a sinusoid by decimation Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 f0xc85e 9 6 Oxc85f 6 615 Io include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const M 10 var dm circ s M downsampling ratio fs_low fs M low rate sampling pulse train const D 2000 var dm circ sine D basic frequency increment fs D 4 Hz sinusoidal wavetable from sinetbl hexj const FS 8000 fast sampling rate in samples sec const c 250 f c fs D c 4 1000 Hz const T 4 desired total duration in seconds var dm N N fs T no of samples in T sec 4 EXPERIMENTS 22 4 EXPERIMENTS 23 axl T FS N T FS duration in samples program and listen to the output This experiment works better if you run it
39. What is its decimal value d On occasion you can hear quantization overflow effects especially when the input gets too strong Introduce appropriate scaling factors for each plain re verb filter and replace the allpass filters by their transposed forms Recompile and run Have you managed to eliminate the overflow effects 4 9 Stereo Reverb In several of the previous experiments we considered processing in stereo In those cases the left and right channels were processed completely independently of each other In this experiment we allow the cross coupling of the two channels so that the reverb characteristics of one channel influences those of the other An example of such system is given in Problems 8 22 and 8 23 and depicted in Fig 8 4 1 of the text 1 Here we assume that the feedback filters are plain multiplier gains so that Gr Z AL Gr Z ar Each channel has its own delay line buffer and circular pointer The sample processing algorithm is modified now to take in a pair of stereo inputs and produce a pair of stereo outputs for each input stereo pair XL XR do Si tap L wL PL L SRR tap R wr Pr R YL CLXL SLL YR CRXR SRR P Sro D X ALSLL RSRR PR SRo DRXR ARSRR LSLL cdelay L wr amp pr cdelay R Wr amp Pr where L and R denote the left and right delays Cross coupling between the chan nels arises because of the coefficients dz and dx The fol
40. a command line option that allows one to select this type of square wave Using again the techniques of Section 9 7 we find for its inverse DFT expansion y 0 4 sin Ww Nn wo sin wn tan tan 2 2 v n where now only pure sines as opposed to sines and cosines appear The difference between the above two square waves contains the effect of the discontinuities and is given by v n 1 0 0 0 0 1 0 0 0 0 Its discrete Fourier series is the difference of the above two v n 0 4 cos Ww n 0 4 cos w3n 0 2 cos w5n Lab Procedure a Go to subdirectory c adi_dsp examples notch Generate two square waveta bles of the above two types by the DOS commands squartbl 1 1 400 800 1 dec2hex 1 15 gt squartb1 hex squartbl 1 1 400 800 O dec2hex 1 15 gt squartb2 hex Compile and run the program notch dsp with the filter off Speak into the mike and listen to the interference Repeat with the filter on Repeat with the filter on but using the second wavetable Turn off the interference by setting its amplitude A 0 and listen to the effect the filter has on your voice input 4 EXPERIMENTS 74 b Estimate the 60 dB time constant in seconds of the filter in part a Redesign the notch filter so that its 3 dB width is now Af 2 Hz What is the new time constant Run the new filter and listen to the filter transients as the steady state gradually takes over and suppresses the noise Turn off t
41. address is incre mented or decremented automatically by an amount specified by the value of the M register For example the instruction mri dm i2 m2 writes into mr1 the contents of the DM memory location pointed to by i2 and then changes 12 by an amount m2 If m2 1 then the new 12 will point to the next mem ory location and if m2 1 it will point to the previous location This post modify scheme applies also to writing into memory For example the instruction dm i2 m2 mri writes the contents of mr1 into the memory location pointed to by 12 and then changes i2 by an amount m2 A useful related instruction is the modi fy instruction which allows 12 to be changed by a desired amount m2 without reading or writing data modify i2 m2 The DAG registers can keep track of the memory locations for both linear and cir cular buffer arrays Thus they are especially convenient for implementing circular delay line buffers Fig 3 2 shows how the DAG pointer 12 points into a circular buffer just like the usual pointer p of the text 1 The value of m2 specifies by how much 12 is to move As i2 moves up or down within the buffer locations it wraps around automatically if it exceeds the upper or lower bounds 3 INSTRUCTION SET TUTORIAL 10 DM Wo Wi circular DAG1 12 Wa lt p wq buffer 10 mo LO w il mi Lt oe A i2 m2 L2 13 m3 L3 d Fig 3 2
42. aliasing effects the circular buffer implementation of delays FIR and IIR filters the canceling of periodic interference with notch filters wavetable generators and several audio effects such as comb filters flangers and phasers plain allpass and lowpass reverberators Schroeder s reverberator and several multi tap multi delay and stereo delay type effects as well as the Karplus Strong string algorithm All of the experiments are based on the text 1 Our aim in these experiments is not to necessarily write the most efficient as sembly code but rather to show beginning DSP students how straightforward and fun itis to program a DSP chip and hear the algorithms in action Thus we have at times sacrificed efficiency for clarity To facilitate the programming of these applications we have written a number of assembly code macros that closely parallel some of the C routines in the text such as cdelay and tap and allow the manipulation of circular delay line buffers and the building up of more complex block diagrams Our use of circular buffers and pointers is identical to that in the text e g filter coefficients and states are stored in forward order and a delay is implemented by decrementing the buffer pointer A number of DOS utilities are also included such as decimal to hex format converters and wavetable generators All of the included programs are based on the talkthru example program given in the EZ KIT Lite Reference Manua
43. assembly code plain dsp plain reverb IIR comb filter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on plain c of Introduction to Signal Processing Sample processing algorithm from Eq 8 2 14 and Fig 8 2 6 for each x do sD tap D w p D get D th tap y x a sD filter output tap i2 m2 D my0 mxO al mr mr mxO my0 rnd if mv sat mr srO mrl my0 s1 D th tap mr sO x al s1 saturate mr if overflow sr0 s0 p y put y into tap 0 cdelay D w amp p update delay define sampling rate in kHz 38 4 EXPERIMENTS 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 oan nn nnn nnn nnn nnn nnn nnn nnn nnn nen include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a 0x4000 feedback coefficient a 0 50 const D 3000 TD D fs 3 8 0 375 sec var dm circ w D 1 delay line buffer i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples wait idle jump wait wait for inte
44. ax0 initialize w1 to zero Then the sample processing algorithm for the right channel only will be myO dm rx_buf 2 get right input from codec 3 INSTRUCTION SET TUTORIAL 9 mx0 b read filter coefficient b into my0 mr mx0 myO ss mr b x mx0 a read filter coefficient a my0 dm w1 get internal state from DM mr mr mxO myO rnd mr y a wl b x output sample dm w1 mri update state wl y dm tx_buf 2 mri send right output to codec Note that after the final MAC only the rounded 16 bit MSB part of mr contained in mri is sent to the codec and saved into the internal state memory location 3 3 DAG Registers and Circular Buffers Another way to transfer data back and forth from DM or PM memory is indirectly via the two sets of data address generator DAG registers The address pointers or index I registers 10 11 12 13 are associated with DAG1 and can point only to DM memory whereas 14 15 16 17 are associated with DAG2 and can point either to DM or PM memory Associated with these address pointers we also have the corresponding modify M registers m0 m1 m2 m3 and m4 m5 m6 m7 and the corresponding length L registers LO L1 L2 L3 and L4 L5 L6 L7 They are all 14 bit registers Note that 10 and 11 are reserved in the EZ KIT Lite The data memory location pointed to by an I register can be accessed by the instruction dm I M where after the access read or write the
45. c of Introduction to Signal Processing define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 include lt c adi_dsp macros begin dsp gt initializations and DSP macros 4 EXPERIMENTS 29 zero i3 m3 L3 clear right delay line read coefficients in 1 15 hex format from file fir hex start processing input samples nit hi lt fir hex gt wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 mx1 dm rx_buf 2 left input sample right input sample sample processing algorithm process right input only cfir M 14 m4 12 m2 axl input from ax1 output in mr1 ayl mrl left output cfir M 14 m4 13 m3 mx1 input from mx1 output in mr1 myl mri right output write output samples to codec dm tx_buf 1 ayl dm tx_buf 2 my
46. dm rx_buf 2 right input sample uration of the delay in seconds now sample processing algorithm process right channel only c Reset the sampling rate back to 8 kHz and this time change d to its maximum value d D 6000 Recompile reload and listen to the impulse response tap i2 m2 d my1 d th tap output into my1 Experiment with lower and lower values of d and listen to your delayed voice tapinli2s mas ma Tinp t Fromme into tap 10 until you can no longer distinguish a separate echo How many milliseconds cdelay i2 m2 update delay i of delay does this correspond to write output samples to codec d Set d 0 recompile and reload It should correspond to no delay at all that dm tx_buf 1 my1 left output sample is y n X n But what do you hear Can you explain why Can you fix it by dm tx_buf 2 my1 right output sample changing the program Will your modified program still work with d 0 Is e in a A there any good reason for structuring the program the way it was originally rti 5 4 3 FIR Filters include lt c adi_dsp macros end dsp gt wrapup The initial version of the program outputs the 2000th tap that is the signal y n x n d corresponding to a time delay in seconds Tg dT d fs 2000 8000 0 25 sec The sample processing algorithm in the notation of the text 1 is
47. double length circular buffer 14 should be declared as var pm circ a M 1 b M 1 14 Aa L4 2 M 1 The program assumes that numerator and denominator have order M The delay line buffer must be declared as follows var dm circ w M 1 i2 Aw L2 w typical usage ccan M 14 m4 12 m2 ea eb axl internal operation 5 MACROS 103 mxl axl mri 0 tapin i2 m2 mr1 dot M 14 m4 12 m2 sr ashift mr1 by ea hi mr 0 mri srl myO 0x8000 mr mr mx1 my0 rnd if mv sat mr ar mrl tapin i2 m2 ar dot M 14 m4 12 m2 sr ashift mr1 by eb hi cdelay i2 m2 macro ccan 0 1 2 3 4 5 6 7 mx1 7 mx1 input x mr1 0 tapin 3 4 mr1 put s0 0 into tap 0 dot 0 1 2 3 4 mr1 dot M a s sr ashift mr1 by 5 hi srl Ga dot M a s mr 0 mr1 srl mr Ga dot M a s my0 0x8000 facilitates MAC usage mr mr mx1 my0 rnd mr Ga dot M a s x if mv sat mr ar mr1 ar sO x Ga dot M a s tapin 3 4 ar input sO into tap 0 dot 0 1 2 3 4 mr1 dot M b s sr ashift mr1 by 6 Chi srl y Gb dot M b s cdelay 3 4 endmacro Fig 5 1 shows this realization together with the necessary scale factors To fit within the 1 15 format the filter coefficients must be scaled by appropriate factors of the form Ga 2 Gp 2 The scaled and u
48. dsp from the macros subdirectory The template file includes all the necessary DSP processor and codec initializations The student can then enter his her choice of sampling rate fs and insert a signal processing algorithm at the appropriate places inside the file Several sampling rates may be selected such as fs 8 16 32 44 1 48 kHz and more 2 GETTING STARTED 3 2 2 Decimal to Hex Format Converters The two DOS programs dec2hex exe and hex2dec exe allow the conversion from decimal format to 1 15 or in general a b hexadecimal format and vice versa Their C source code uses the routines adc c and dac c from 1 and is included in the Appendix Both programs can receive their input from stdin or from an input file con taining the numbers to be converted separated by spaces tabs or newlines They return their output to stdout or an output file Typical usage examples are dec2hex 1 15 lt data dec gt data hex dec2hex 2 14 lt data dec gt data hex dec2hex 1 15 where data dec is a file containing the decimal numbers to be converted to the 1 15 format or the 2 14 format in the second case and the file data hex con tains the corresponding hex numbers In the third case the user must enter each decimal number or a group of numbers separated by spaces in the command line followed by lt RET gt and enter a lt CTRL Z gt or lt CTRL C gt after the last number has been processed Similarly the usage of hex2dec is a
49. fir hex recompile and reload Speak into the mike The filter will cut off the higher pitches in your voice but it also introduces a perceptible delay in the output This delay was too short to be heard for the first filter Through their phase response all filters introduce a certain amount of delay which depends on the frequency of the input FIR filters can be designed to have linear phase which implies that all frequency components of the input get delayed by the same amount and thus the input as a whole gets delayed For a linear phase FIR filter of order M the amount of delay is M M M D gt gt o Thus how much is the delay in seconds for filter 1 and filter 2 c Next run program fir3 dsp with the order 206 filter First listen to the unfiltered sinusoid f1 This can be done by commenting out the cf ir call and replacing the sinusoid amplitudes by A 1 0x7fff in hex and A 0 Then listen to the unfiltered component f2 and then to the unfiltered sum of both Finally uncomment cfir and send in the sum of the two You will hear only the f component at the output 4 4 Comb Filters This experiment implements the FIR comb filter given by Eq 8 2 8 of the text 1 y n x n ax n D a x n 2D a x n 3D Its transfer function is H z 1 az a P a zP This filter can be implemented using the program fir dsp of the previous experi ment as a general FIR filter with an impulse response
50. for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec mrO dm rx_buf 1 left input sample mr1 dm rx_buf 2 right input sample sample processing algorithm sr ashift mr0 by L Chi shift right by L bits sr ashift srl by L Chi shift left by L bits mrO srl requantized left sample sr ashift mr1 by L Chi shift right by L bits sr ashift srl by L Chi shift left by L bits mr1 srl requantized right sample write output samples to codec dm tx_buf 1 mrO left output sample dm tx_buf 2 mrl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The input samples from the codec are available in 16 bit resolution In this experi ment each input sample is re quantized to B bit resolution where 1 lt B lt 16 and then it is sent out to the codec The number of least significant bits that are thrown away are L 16 B The re quantization operation is done conveniently by the shifter by first shifting to the right by L bits and then shifting to the left by L bits This has the effect of filling the last L bits with zeros The simulator program quantex
51. format 4 dimensional linear buffer w i 1 0 1 2 3 temporary variables Then the following examples of data transfers are all executable in one cycle each mr1 0 load mr1 with zero myl a load my1 with the constant a axl 0x4000 load ax1 with the value 0x4000 0 50 in decimal ar srl load ar with content of sri mx1 ay0 load mx1 with content of ay0 mr1 dm x load mr1 with content of DM location x dm y my1 load DM location y with the content of my1 mr1 dm w load mr1 with content of buffer location w 0 mr1 dm w 1 load mr1 with content of buffer location w 1 dm w 2 mri load buffer location w 2 with content of mr1 As a signal processing example consider the implementation of the first order filter y n ay n 1 bx n where a 0 75 b 0 25 3 INSTRUCTION SET TUTORIAL 8 Introducing the internal state w n y n 1 and noting that the next state is w n 1 y n we may draw a block diagram realization and write the sample processing algorithm as follows x b ase y for each input sample x do z y aw bx a wi Wi y To implement this example on the EZ KIT Lite board we must be able to read input samples from the codec and write the output samples back to the codec In the sample talkthru program from the EZ KIT Lite Manual 2 this is accom plished by using the so called autobuffering technique of the ADSP 2181 s
52. is executable on the 2181 chip not under DOS 3 Loading the executable file onto the chip via the serial connection using Dwight Elvey s public domain loader program ez1d com found in 3 The operation has again been automated by a batch file ez1 bat and is invoked from DOS as follows ezl filename This loads filename exe onto the processor and begins execution immedi ately One can also load the program and enter a menu oriented terminal program by the command ezl filename t The above utilities are in the path and can be executed from any subdirectory The doskey synonym dsp changes to the directory c ladi_dsplexamples below which are the subdirectories of the various examples There are a number of other useful utilities available The batch file ezs bat will compile and link a source code file and then run the simulator sim2181 exe ezs filename where the full name filename dspis assumed Some simulator example programs are in the examples subdirectory sim The examples include quantization and downsampling an order 3 delay an FIR and an IIR filter implemented using circu lar buffers In the simulator one can step through every instruction in the program and observe the contents of the delay line buffer registers as they change from one input sample to the next There is also the DOS batch file mkezk bat with usage mkezk filename It generates the file filename dsp by copying into it a template file template
53. is used to generate both the parameter c t and the modulated signal x t The modulation frequency is fm Cmfs D where Cm 1 resulting in fm 2 Hz fm dsp FM modulation of using common sinusoidal wavetable Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Sec 8 1 3 of Introduction to Signal Processing choose sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const D 4000 var dm circ sine D min frequency f1 fs D 8 4 2 Hz load one period of the wavetable generated by sinetb1 cj Cconst Am 30 Am 0 30 cO const cm 1 fm cm fs D 2 Hz init sine lt sinetbl hex gt 15 Asine L5 sine pointer for frequency generator 4 EXPERIMENTS 68 const A 0x4000 const c0 100 A 0 50 signal amplitude signal freq fO cO f1 200 Hz 16 Asine L6 sine pointer for signal generator start processing input samples wait idle jump wait wait for interrupt and loop forever inter
54. rep mx1 dm rx_buf 2 right input sample resented approximately by 0x7fff in 1 15 format whereas 1 is represented exactly by 0x8000 sample processing algorithm process right channel only i dl d The FIR comb filter can also be implemented as an ordinary FIR filter without Md pe my1 ss fie Sab 3 taking into account the sparseness of its impulse response h In this part define the 3D 1 dimensional impulse response tap i2 m2 D my0 my0 s1 D th tap mx0 al 2 3 mr mr mx0 my0 ss mr a0 x al s1 h 1 0 0 0 4 0 0 0 a 0 0 0 a RA F D 1 zeros D 1 zeros D 1 zeros tap i2 m2 2 D my0 myO s2 2D th tap mx0 a2 a mr mr mxO my0 ss mr a0 x al sl a2 s2 and assign it to a circular buffer in PM Then use the program fir dsp of the previous section to implement this filter Compile and run with the value a 3 D my0 my0 s3 3D th tap D 2000 so that you may compare its output with that of comb dsp TO x0 e E o ee tee ae Sat e The FIR comb can also be implemented recursively using the geometric series if mv sat mr saturate mr if overflow ae p E formula to rewrite its transfer function in the recursive form tapin i2 m2 mx1 put input from mx1 into tap 0 cdelay i2 m2 update delay 1 atz PD H z 1lt az 07 az A write output samples to codec 1 az dmCtx_buf 1
55. sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 a i oe include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers 4 EXPERIMENTS 61 const al 0x199a al 0 20 const a2 0x4000 a2 0 50 const bO Ox7fff b0 0 9999 that is 1 const b1 0x6666 b1 0 80 const b2 Ox4ccd b2 0 60 const D1 3000 D1 fs 3000 8000 0 375 sec const D2 4500 D1 D2 7500 7500 8000 0 9375 sec var dm circ w D1 D2 1 delay line buffer i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples wait for interrupt and loop forever interrupt service routine starts here enable secondary register set wait idle jump wait input_samples ena sec_reg read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only tap i2 m2 D1 sr0 tap i2 m2 D1 D2 sri
56. signal frequency f c f1 200 Hz 16 Asine L6 sine pointer for signal generator start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set sample processing algorithm wavgen i6 m6 A c mx1 mx1 A sin 2 pi f t write output samples to codec dm tx_buf 1 mx1 left output sample dm tx_buf 2 mx1 right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The sinusoidal wavetable has period D 4000 andis read from the file sinetb1 hex which was generated by the DOS commands sinetb1 O 1 4000 gt sinetb1 dec dec2hex 1 15 lt sinetbl dec gt sinetbl hex Therefore the smallest frequency that can be generated by the wavetable at an 8 kHz sampling rate is f fs D 8000 4000 2 Hz Higher frequencies can be selected by the parameter c resulting in f cf cfs D At each sampling instant the program does nothing with the codec inputs In stead it generates a sample of a sinusoid by a call to wavgen and sends it to the codec 4 EXPERIMENTS 66 AM Modulation The next program am dsp illustrates AM modulation The envel
57. use with tap buffer e g m4 3 pointer to y delay line buffer in DM e g i2 4 m register to use with y delay buffer e g m2 5 pointer to x delay line buffer in DM e g 13 6 m register to use with x delay buffer e g m3 7 8 9 exponent for a coefficient scale factor exponent for b coefficient scale factor data register holding input e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri sr0 srl The filter output is returned in AR The input may need to be scaled down further to avoid overflows Upon exit the delay line pointer i2 is decremented The filter coefficients must be stored consecutively in the order a0 al a2 aM bO b1 bM and i4 is points to this double length buffer The a b coefficients used in the program are related to the true a b coefficients by the scale factors defined by the exponents ea eb a_true Ga Ga 2Aea scale factor b_true Gb Gb 2Aeb scale factor a b I I I because a0_true 1 it follows that a0 1 Ga This coefficient is redundant and not really used in the computation it always gets multiplied by zero The common double length circular buffer 14 should be declared as var pm circ a M 1 b M 1 14 Aa L4 2 M 1 Program assumes that both numerator and denominator have order M The y and x delay line buffers must be declared as follows var dm circ w M 1 var dm circ v M 1 12 Aw L2 w 13 Av L3 v
58. x input x dm x i parallel outputs x_i i2 Awl L2 wl 13 Aw2 L3 w2 14 Aw3 L4 w3 15 Aw4 L5 w4 16 Aw5 L6 w5 17 Aw6 L7 w6 zero i2 m2 L2 zero i3 m3 L3 zero i4 m4 L4 zero i5 m5 L5 zero i6 m6 L6 zero i7 m7 L7 start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only si mxl read current input into SI sr ashift si by 3 Chi scale x down by a factor of 8 dm x srl save x 4 EXPERIMENTS 50 4 EXPERIMENTS 51 plain 1 mr 0 mxO bl my0 dm x 1 mr 0 mr mr mxO myO ss mr b1 x1 mr1 dm x mr x input mxO b2 my0 dm x 2 mx1 al mr mr mx0 my0 ss mr b1 x1 b2 x2 tap i2 m2 D1 my1 my1 sD1 D1 th tap mr mr mx1 my1 rnd mr x1 x al sD1 mxO b3 my0 dm x 3 mr mr mxO my0 ss mr b1 x1 b2 x2 b2 x2 tapin i2 m2 mr1 put x1 into tap 0 cdelay i2 m2 update delay mxO b
59. 0 84375 0x6c00 27 32 0 000 0x0000 0 8 0 87500 0x7000 28 32 0 000 0x0000 0 8 0 90625 0x7400 29 32 0 000 0x0000 0 8 0 84375 0x6c00 27 32 The b coefficients and x have been scaled down to fit in 1 15 format as compared to Example 7 5 4 Scaling factors The a b coefficients that are used in the program and read from the file ab hex are the related to the true a b coefficients by the following scale factors whoes exponents are passed to ccan a_used 2A ea a_true b_used 2A eb b_true 94 4 EXPERIMENTS rti start 12 i4 i5 17 nop Aw AX Ay Aa nop nop L2 w m4 1 m5 1 zero i2 m2 L2 cntr do outputs until ce outputs L srl dm i4 m4 sr ashift srl ccan M 17 m7 12 m2 ea eb srl sr In this example ea 0 eb 0 no further scaling is needed The input samples x must also in general be scaled down before passed into ccan and then the output from ccan must be scaled up x1 2A ex x input to ccan yl ccan x1 output from ccan due to x1 y 2Aex yl output due to x In this example we must use ex 1 Cor larger The unscaled input ex 0 causes overflows and the wrong output include lt c adi_dsp macros dspmac dsp gt dsp macros module ram abs 0 canex1 const L 9 input signal length const M 3 filter order var dm x L input samples var dm y L output sample
60. 1 left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup FIR Filtering of Sinusoids Finally we consider a third version of the FIR filtering program fir3 dsp that uses the concept of wavetable generators from Section 8 1 3 of the text 1 fir3 dsp FIR filtering of sinusoids generated by circular wavetable Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based of cfir c and Sec 8 1 3 of Introduction to Signal Processing define constants variables and buffers const M 206 designed by firlp m or firhp m var dm circ wL M 1 left delay line buffer in DM var dm circ wR M 1 right delay line buffer in DM var pm circ h M 1 filter coefficient buffer in PM i2 AwL L2 wL delay line buffer pointer and length 13 MR L3 wR delay line buffer pointer and length 14 Ah L4 h coefficient buffer pointer and length zero i2 m2 L2 clear left delay line define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 nono nnn nnn nnn nn nnn nnn nnn nnn nnn nn
61. 1 dsp in the examples subdirectory sim steps through such a re quantization operation Lab Procedure a Still in the c adi_dsp examples quantize directory compile and run the above program with an initial choice of B 6 bits Speak into the mike and listen to the quantization noise Repeat the above procedure by editing the program and choosing the succes sive values B 16 15 1 For the higher values of B you will probably 4 EXPERIMENTS 19 not hear any quantization noise The noise should become more and more evident as you decrease B especially below 8 bits Make sure you listen to 1 bit and 2 bit speech The quantization operation is an example of a nonlinear memoryless opera tion on each input sample Other examples of such nonlinear operations can be tried out As a distortion example modify the above program so that instead of quan tizing each sample it squares it that is y n x n and then it sends y n to the output Compile and run this program Can you understand the types of distortions you are hearing in the frequency domain Repeat when each input sample is cubed that is y n x n You may need to scale up the output y n using the shifter Aliasing by Downsampling The following program dnsample dsp implements a downsampling operation where the sampling rate is reduced by a factor of M dnsample dsp downsampling and aliasing by decimation Junior DSP Lab Rutgers ECE Dept S J Orfa
62. 15 lt decimal dat gt hex dat An 6 APPENDIX 109 puts In the 1 15 format the range is 1 lt x lt 1 2A 15 puts and in hex 1 8000 1 2A 15 7fff puts nTotal number of bits B a b must be a multiple of 4 puts Full scale range is R 2Aa puts Outputs have B 4 hex digits n puts The B bits b_1 b_2 b_B represent the number puts x 2A a 1 b_1 2Af a 2 b_2 2A b b_B puts The limits are puts 2A a 1 lt x lt 2A a 1 2A b puts e g in 4 12 format 8 lt x lt 8 2A 12 n exit 0 J a atoi argv 1 B a atoi strchr argv 1 1 total bits R pow 2 a 2Aa full scale b int calloc B sizeof int B bit vector h int calloc B 4 sizeof int B 4 hex digits while fscanf stdin 1f amp x EOF adc x b B R for i 0 i lt B 4 i h i 8 b 4 i 4 b 4 i 1 2 b 4 i 2 b 4 1 3 printf x h i convert to binary 3 printfC n 3 The program hex2dec c performs the converse operation that is hex to decimal conversion For each hex number to be converted it reads its hex digits as chars then works out the binary bit pattern of the number and then calls the text routine dac c to convert it to decimal Again one must have a b B where the program assumes that there will be B 4 hex chars in each hex number to be converted hex2dec c hex to decimal
63. 2 m2 0 macro zero 0 1 2 local loop cntr 2 1 1 do loop until ce loop dm 0 1 0 endmacro 5 2 tap The macro tap allows the accessing of the tap outputs of a delay line and is modeled after the routines tap c and tap2 c of the text 1 tap dsp tap outputs of circular delay line Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on tap c and tap2 c of Introduction to Signal Processing 0 pointer to delay line buffer e g 12 1 M register to use with buffer e g m2 2 d for d th tap content where d 1 D 3 data register for result e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri srl typical usage tap i2 m2 d srl put d th tap content into SR1 note i2 is not changed internal operation modify i2 m2 srl dm 12 m2 point to d th tap put d th tap in data register and restore i2 to its entry value 5 MACROS 99 macro tap 0 1 2 3 1 2 modify 0 1 1 2 3 dm 0 1 point to d th tap put d th tap in data register endmacro 5 3 tapin The macro tapin transfers the content of a data register into tap 0 of a delay line The analogous statement in the textis p x which puts x into the buffer location pointed to by the pointer p Here the role of the pointer is played by the I register tapin dsp put input sample into tap 0 of delay line Junior DSP Lab Rutgers ECE Dept S J Orfanid
64. 3 m3 mr1 put s20 into tap 0 of delay 2 const al 0x4000 al 0 50 cdelay i3 m3 update delay 2 const a2 0x3333 a2 0 40 mr Di const b0 Ox7fff b0 0 9999 that is 1 mr1 mx1 mr x const b1 0x6666 b1 0 80 myO al const b2 0x4ccd b2 0 60 mr mr srO myO rnd mr s10 x al s1D if mv sat mr const D1 3000 tapin i2 m2 mr1 put s10 into tap 0 of delay 1 const D2 4000 cdelay i2 m2 update delay 1 var dm circ w1 D1 1 delay 1 buffer return from interrupt var dm circ w2 D24 1 delay 2 buffer rti i2 Awl L2 wl delay line buffer pointer and length 13 Aw2 L3 w2 delay line buffer pointer and length include lt c adi_dsp macros end dsp gt wrapup zero i2 m2 L2 clear delay 1 zero i3 m3 L3 clear delay 2 Lab Procedure start processing input samples a Go to the directory c adi_dsp examples multidel Compile and run this program Listen to its impulse response and speak into the mike wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here b Set b 0 and run again Then set bz O and run Can you explain what input_samples ena sec_reg enable secondary register set you hear read input samples from codec axl dm rx_buf 1 left input sample
65. 4 my0 dm x 4 mr mr mxO myO rnd x5 b1 x1 b2 x2 b2 x2 b4 x4 dm x 1 mri save x1 for later usage if mv sat mr mr x5 plain 2 allpass 1 mr 0 myO a5 mr1 dm x mr x input tap i6 m6 D5 mx0 mx0 sD5 D5 th tap mr mr mxO myO rnd mr s05 x5 a5 sD5 mx1 a2 tap i3 m3 D2 my1 my1 sD2 D2 th tap tapin i6 m6 mr1 put s05 in tap 0 of delay D5 mr mr mx1 my1 rnd mr x2 x a2 sD2 cdelay i6 m6 update delay tapin i3 m3 mrl put x2 into tap 0 mr mri my0 rnd mr a5 s05 cdelay i3 m3 update delay ayO mx0 fay0 sD5 ar ay0 mri far x6 sD5 a5 s05 dm x 2 mri save x2 for later usage allpass 2 plain 3 mr 0 mr 0 mrl ar mr x6 input mr1 dm x mr x input myO a6 mx1 a3 tap i7 m7 D6 mx0 mx0 sD6 D6 th tap tap i4 m4 D3 my1 my1 sD3 D3 th tap mr mr mxO myO rnd mr s60 x6 a6 sD6 mr mr mx1 my1 rnd mr x3 x a3 sD3 tapin i7 m7 mr1 put s06 in tap 0 tapin i4 m4 mr1 put x3 into tap 0 cdelay i7 m7 update delay cdelay i4 m4 update delay mr mri my0 rnd mr
66. 5 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers var dm v1 state of first order feedback filter const a 0x4000 a 0 50 const b0 0x199a b0 0 20 const b1 Ox0ccd b1 0 10 const D 3000 TD D fs 3 8 0 375 sec var dm circ w D 1 circular delay line i2 Aw L2 w delay line buffer pointer and length ax0 0 dm v1 ax0 clear feedback delay v1 0 zero i2 m2 L2 clear delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only tap i2 m2 D mr mx0 a myl dm v1 mr mr mxO my1 rnd if mv sat mr srO mrl my0 b0 mr mr1 my0 ss mx0 bl mr mr mx0 my1 rnd if mv sat mr ayl mx1 ar mrl ayl mr1 sD
67. Cin rads sample Sweep frequency fsweep 10 Hz Because w0 varies between 0 20 pi lt w0 lt 0 05 pi we can use the approximation cos w0 1 w042 2 define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 Cconst fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 4 EXPERIMENTS include lt c adi_dsp macros begin dsp gt 83 initializations and DSP macros define constants variables and buffers var dm circ w 3 var dm circ v 3 var pm circ a 3 b 3 const ea 1 const eb 1 const ex 1 i2 Aw L2 w 13 Av L3 v 14 Aa L4 6 zero i2 m2 L2 zero i3 m3 L3 const Ds 4000 var dm circ s Ds 16 As L6 s Cconst csweep 5 const wl 0x3244 Cconst w2 0x1e28 const bO 0x3e0c const b11 0x83e7 const a2 0x3c19 const a0 0x4000 init s lt sinetbl hex gt init a a0 0 a2 init b b0 0 b0 start processing input samples wait idle jump wait input_samples ena sec_reg read input samples from codec axl dm rx_buf 1 mx1 dm rx_buf 2 sample processing algorithm ax0 w
68. D th tap state v1 mr v0 sD a v1 save vO for later updating v1 mr bO vO mr u bO vO b1 v1 ayl x input ar y x u output 4 EXPERIMENTS 48 dm v1 sr0 update lowpass filter v1 v0 tapin i2 m2 ar put y in tap 0 cdelay i2 m2 update delay write output samples to codec dm tx_buf 1 ar left output sample dm tx_buf 2 ar right output sample return from interrupt rei include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Go to the directory c adi_dsp examples lowpass Using the parameters D 3000 a 0 5 b 0 20 b 0 10 compile and run this program Listen to its impulse response Speak into the mike Notice how successive echoes get more and more mellow as they circulate through the lowpass filter b Try the case D 20 a 0 b by 0 49 You will hear a guitar like sound Repeat for D 40 and D 80 What do you hear We will encounter these cases again in making a model of a guitar string 4 8 Schroeder s Reverb A more realistic reverberation effect can be achieved using Schroeder s model of reverberation which consists of several plain reverb units in parallel followed by several allpass units in series An example is shown in Fig 8 2 18 of the text 1 Its sample processing algorithm is given by E
69. DAG pointer into a circular delay line buffer 3 4 Defining and Initializing a Delay To implement a delay of some maximum amount say D 100 samples one must declare it as a circular D 1 dimensional array then set one of the I registers to point to the beginning of the buffer and define the corresponding L register to contain the length of the buffer const D 100 var dm circ w D 1 placed in DM memory i2 L2 w i2 initially points to beginning of w w L2 is set equal to the length of w toil The buffer may be initialized to zero by the do loop m2 1 post increment i2 by one cntr L2 do loop until ce loop dm i2 m2 0 repeat until counter expires put O in dm i2 m2 and point to next i2 The do loop iterates L2 times and therefore because the buffer is circular the pointer 12 will wrap around completely and upon exit it will be pointing again at the beginning of the buffer w This initialization loop has been made into a macro zero dsp and is invoked by zero i2 m2 L2 3 5 Reading and Writing a Delay Line Buffer Once the circular buffer w and pointer 12 have been defined the delay line s tap outputs can be obtained by accessing the buffer entries relative to i2 For example the value contained in the d th tap can be obtained by the instructions modify i2 m2 d go to location pointed to by i2 d d mr1 dm 12 m2 m2 2 put its content in mr1 then restore
70. Dy Up X xPw So 0 Pw Y So Gpdot M b u Ggdot M a s cdelay M v amp py cdelay M w amp pw where py and py are the x delay and y delay buffer pointers v w are the corre sponding buffers and u s the corresponding states relative to the current values of the pointers 5 9 wavgen The macro wavgen implements a wavetable generator as discussed in Section 8 1 3 of the text 1 To facilitate the usage of the DAG registers the wavetable circular buffer is loaded and circulated in forward order If the wavetable has length D and the address increment is c then the wavetable is cycled over every c of its samples generating a waveform of basic frequency f Cp The stored waveform is scaled by the amplitude factor A By assigning two different DAG registers to the wavetable and two different address increments one can generate waveforms of two different frequencies wavgen dsp wavetable generator Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on wavgen c of Introduction to Signal Processing Sec 8 1 3 0 pointer to wavetable buffer e g 15 1 m register to use with buffer e g m5 2 desired amplitude A 3 desired increment c frequency f c fs D 4 data register holding output e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri sr0 srl registers mx0 my0 are altered typical usage wavgen i5 m5 A c my1 internal operation m5 C3 mx0 A
71. L 0x4000 cL 0 5 left direct path gain const CR 0x4000 cR 0 5 right direct path gain const dL 0x4000 dL 0 5 cross feedback from L to R const dR 0x4000 dR 0 5 cross feedback from R to L const L 3000 TL L fs 3 8 0 375 sec const R 3000 TR R fs 3 8 0 375 sec var dm circ wL L 1 left delay line buffer var dm circ wR R 1 right delay line buffer 12 13 AwL L2 wL AwR L3 wR delay line buffer pointer and length zero i2 m2 L2 zero i3 m3 L3 clear delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set 4 EXPERIMENTS 54 read input samples from codec mxO dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm tap i2 m2 L sr0 tap i3 m3 R srl mr 0 mri sr0 myO cL mr mr mxO my0 rnd if mv sat mr dm tx_buf 1 mrl mr 0 mri srl my0 cR mr mr mx1 my0 rnd if mv sat mr dm tx_buf 2 mrl my0 bL mr mx0 my0 ss my0 aL mr mr srO my0 ss my0 dR mr mr srl my0 rnd if mv sat mr tapin i2 m2 mr1 cdelay
72. RUTGERS UNIVERSITY The State University of New Jersey School of Engineering Department of Electrical and Computer Engineering 94 Brett Road Piscataway NJ 08854 8058 Tel 732 445 5017 e mail orfanidi ece rutgers edu 332 348 Digital Signal Processing Laboratory Spring 2006 ADSP 2181 Experiments Sophocles J Orfanidis ADSP 2181 DSP ee A a AD1847 sample buf la analog input processing y codec algorithm tx buf gt gt analog output ee P Copyright 1996 2006 by S J Orfanidis http www ece rutgers edu orfanidi ezkitl ezkit1l html Contents 1 Introduction 2 Getting Started 2 1 2 2 2 3 2 4 Running DSP Programs e Decimal to Hex Format Converters o e Wavetable Generator Programs o e Subdirectory Structure 2 et 3 Instruction Set Tutorial 5 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 Computational Units aaoo e a es Data Transfers ase cn a a a aa DAG Registers and Circular Buffers a ooo o o Defining and Initializing a Delay Reading and Writing a Delay Line Buffer Updating a Delay coozm ocorcrra ma Multifunction Instructions and FIR Filters Linear Delay Line Buffers Concatenated Circular Buffers o e Experiments 4 1 4 2 4
73. Rutgers ECE Dept S J Orfanidis Jan 1996 include lt stdio h gt include lt math h gt void main int argc char argv int i D D1 D2 double A if argc 5 puts nTrapezoidal Wavetable puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n puts Usage trapztbl A D1 D2 D gt file dat n puts A amplitude puts D1 duration of linearly increasing portion puts D2 duration of constant part puts D total period puts D D1 D2 duration of linearly decreasing portion exit 0 3 A atof argv 1 D1 atof argv 2 D2 atoi argv 3 D atoi argv 4 for i 0 i lt D i 6 APPENDIX 113 if Ci lt D1 printf 151f n i A D1 else if Gi lt D1 D2 printf 151f n A else printf 151f n D i A D D1 D2 Finally the program uran c generates a block of uniformly distributed random numbers of any desired mean and range It is useful in designing the random number inputs to the Karplus Strong string algorithm It uses the C function ran c of the text 1 uran c generate block of uniform random numbers Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 range include include include double ranQ void main int argc char m R lt x lt m R lt stdio h gt lt math h gt lt stdlib h gt ran c from I2SP Appendix B argv int N i long i
74. The coefficients and are stored in the files a dec a hex and b output signals are in the files xiir dec xiir MA 375 250 625 500 750 000 000000000 125 000 000 0 1 2 0 4 0 25 0 25 0 50 0 define a double length concatenated circular buffer 17 dec b hex The input and hex yiir dec yiir hex 0x1000 0x3000 0x2000 0x5000 0x4000 0x6000 0x0000 0x0000 0x0000 1 8 3 8 2 8 5 8 4 8 6 8 0 8 0 8 0 8 y 0 0 0 0 0 0 0 0 0 03125 12500 21875 43750 53125 84375 87500 90625 84375 0x0400 1 32 0x1000 4 32 0x1c00 7 32 0x3800 14 32 0x4400 17 32 0x6c00 27 32 0x7000 28 32 0x7400 29 32 0x6c00 27 32 The b coefficients and x have been scaled down to fit as compared to Example 7 5 4 Scaling factors in 1 15 format The a b coefficients that are used in the program and read from 4 EXPERIMENTS 96 5 MACROS 97 the file ab hex are the related to the true a b coefficients by sr ashift srl by ex hi pre scale x down the following scale factors whoes exponents are passed to cdir compute output y cdir M 17 m7 12 m2 13 m3 ea eb srl input in srl a_used 2A ea a_true output in ar b_used 2A eb b_true sr ashift ar by ex hi post scale y up outputs dm i5 m5 srl write y In this example ea 0 eb 0 no further scaling is needed idle The input samples x must al
75. a b format converter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Usage hex2dec a b lt hex dat gt decimal dat include lt stdio h gt include lt math h gt include lt stdlib h gt include lt ctype h gt include lt string h gt double dacQ int c2hQ dac c from I2SP ch 2 void main int argc char argv char s 6 APPENDIX 110 6 APPENDIX 111 int i j a B b in a circular wavetable buffer The C program sinetb1 c generates one period of double x R length D of a sinusoidal or cosinusoidal signal if argc 2 sinetbl c sine wavetable of amplitude A period D samples puts nHex to decimal a b format converter Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n puts Usage hex2dec a b lt hex dat gt decimal dat include lt stdio h gt puts e g hex2dec 1 15 lt hex dat gt decimal dat n include lt math h gt puts Total bits B a b must be a multiple of 4 puts Full scale range is R 2Aa void main int argc char argv puts Inputs must have B 4 hex digits n puts For the a b format the outputs are in the range puts 2A a 1 lt x lt 2A a 1 2A b int c i D STEER double A pi 4 atan 1 0 y if argc 4 a atoi Cargv 1 puts nSine Cosine Wavetable B a atoi strchr argv 1 1 t
76. a6 s06 dm x 3 mri save x3 for later usage ay0 mx0 fay0 sD6 ar ay0 mri far y sD6 a6 s06 plain 4 write output samples to codec mr 0 mr1 dm x mr x input dm tx_buf 1 ar left output sample dm tx_buf 2 ar right output sample mx1 a4 tap i5 m5 D4 my1 my1 sD4 D4 th tap return from interrupt mr mr mx1 my1 rnd mr x4 x a4 sD4 rti tapin i5 m5 mr1 put x4 into tap 0 cdelay i5 m5 update delay include lt c adi_dsp macros end dsp gt wrapup dm x 4 mri save x4 for later usage There are six multiple delays each requiring its own circular buffer and DAG pointer combine parallel outputs of plain sections 4 EXPERIMENTS 52 Lab Procedure a Go to the directory c adi_dsp examples reverb Compile and run this program Listen to its impulse response and speak into the mike b What are the feedback delays of each unit in msec Replace all the delays by double their values compile and run again Compare the output with that of part a Repeat when you triple all the delays Note that you can just replace the constant definitions by const D1 2 291 etc c Repeat parts a b with the following value of the feedback multiplier a 0x7000
77. alf Run the program with frequency f 200 Hz The wavetable amplitude was chosen to be A 1 2 in order to make the rms value of the square wave equal to the rms value of the original sinusoid d Run and listen to the program am dsp with the initial signal frequency of f 200 Hz and envelope frequency of feny 2 Hz Repeat for f 2000 Hz Repeat and explain what you hear for the cases f 200 Hz feny 100 Hz Then f 200 Hz fenv 190 Hz Then f 200 Hz feny 200 Hz 4 EXPERIMENTS 69 e Run and hear the program fm dsp with the following three values of the mod ulation depth Am 0 3C0 Am Co Am 0 1Cg Repeat these cases when the center frequency is changed to f 2000 Hz f Replace the sinusoidal wavetable with the square one squartb1 hex and repeat the case fo 200 Hz Am 0 3Co You will hear a square wave whose frequency switches between a high and a low value two times a second g Keep the square wavetable that generates the alternating frequency but gen erate the signal by a sinusoidal wavetable To do this generate a second sinusoidal wavetable say of length 800 and define a circular buffer for it and set one of the DAG registers e g 16 to point to it Then generate your FM modulated sinusoid using this table The generated signal will be of the form x t sin 27rf t t f t 2 Hz square wave h Rewrite the fir3 dsp program of Section 4 3 using calls to the wavetable generator macro w
78. ample will come out intact whereas the other sam ples will be zero dnsamp1 dsp decimation downsampling example Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 include lt c adi_dsp macros dspmac dsp gt module ram abs 0 deciml Const M 3 const N 8 const A Ox7fff DSP macros decimation ratio number of input samples sampling pulse amplitude A 1 4 EXPERIMENTS var dm x N var dm y N var dm circ s M i2 Ax Hee 1 Le OF i3 Ay m3 1 L3 0 i5 As L5 s m5 1 init x lt x hex gt jump start nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop start cntr M do zero_s until ce zero_s dm i5 m5 0 axl A dm s axl cntr N do output until ce mr1 dm i2 m2 ar dm i5 m5 ar pass ar if ne jump output else mri 0 87 input samples output samples periodic pulse train input samples output samples pulse train read input samples from file Interupt vector table No interrupts used initialize s to zero set s 0 A s A 0 0 A and M 1 zeros process N input samples read input sample get sampling pulse forces updating of AZ flag if AR 0 write output if AR 0 output is 0 output dm i3 m3 mr1 write output sample idle endmod Delay Exa
79. antization Example The program quantex1 dsp implements quantization to B bits If you choose B to be 4 8 and 12 bits you could observe how the algorithm preserves one two or three of the MSB hex digits of each word and sets the remaining digits to zero 4 EXPERIMENTS fquantex1 dsp quantization example 86 Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 include lt c adi_dsp macros dspmac dsp gt module ram abs 0 decim1 Const B 8 Const L 16 B Const N 8 var dm x N var dm y N i2 13 Ax m2 1 L2 0 Ay m3 1 L3 0 init x lt x hex gt DSP macros quantization bits per sample L least significant bits thrown away number of input samples jump start nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop start cntr N do output until ce mrl dm i2 m2 sr ashift mr1 by sr ashift srl by output dm i3 m3 srl idle endmod Downsampling Example L Chi L Chi input samples output samples input samples output samples read input samples from file Interupt vector table No interrupts used process N input samples read input sample shift it right by L bits shift it left by L bits write output sample The program dnsamp1 dsp implements the downsampling operation If you choose M 3 then every third input s
80. avgen Repeat part c of the lab procedure of that Section 4 15 Notch Filters In these experiments we demonstrate the use of filtering for canceling periodic interference The input signal is of the form x n s n v n where s n is the microphone input and v n a periodic interference signal gener ated internally using a wavetable generator Multi Notch Filter When the noise is periodic its energy is concentrated at the harmonics of the fun damental frequency f1 2f1 3f1 and so on To cancel the entire noise component we must use a filter with multiple notches at these harmonics As discussed in Section 8 3 2 of the text 1 a simple design arises when the period of the noise is an integral multiple of the sampling period that is T DT which implies that the fundamental frequency f and its harmonics will be fs f 5 kfi k k 0 1 2 fi D fx Kfi D or in units of radians per sample e 2TT di de 2Trk 1 p k 1 DH These are recognized as the D th root of unity frequencies The corresponding notch filter designed by Eqs 8 3 26 and 8 3 27 of the text has the form 4 EXPERIMENTS 70 1 z7D H z b 12 1 az To avoid overflows we use the transposed realization of this transfer function whose block diagram and sample processing algorithm are shown below x a D y 4 for each input x do Sp Sp tap D w p D z y bx Sp 1 p So
81. ay line b computing the dot product output and c updating the delay line mx1 dm rx_buf 2 read right input from codec tapin i2 m2 mx1 put mx1 into tap 0 of delay line 3 INSTRUCTION SET TUTORIAL 15 DM PM buffer w buffer h Wo A in LA h hi oso Su hs DAGI E s e DAG2 io mo Lo Bi ns i4 m4 LA MSM il mi L1 y i 15 ms5 L5 i2 m2 L2 M M i6 m6 L6 13 m3 L3 i7 m7 L7 Fig 3 6 Dot product y h s of state vector with filter vector dot M 14 m4 12 m2 cdelay i2 m2 compute output into mri update delay sr ashift mri by 2 hi scale output by factor of 2A2 4 dm tx_buf 2 srl write right output to codec The three macros tapin dot and cdelay have been combined into another macro cfir dsp which implements an FIR filter The above example would read in this case mx1 dm rx_buf 2 read right input from codec cfir M 14 m4 12 m2 mx1 input from mx1 output in mr1 sr ashift mr1 by 2 hi scale output by factor of 2A2 4 dm tx_buf 2 srl write right output to codec 3 8 Linear Delay Line Buffers The DAG registers can also point to linear buffers For example the following instructions define the buffer and its pointer const D 100 var dm w D 1 placed in DM memory i2 Aw i2 points to beginni
82. btained by running the lowpass reverb filter with zero input but with initially filling the delay line with random numbers These random numbers model the initial harshness of plucking the string But as the random numbers recirculate through the lowpass filter their high frequencies are gradually removed resulting in a sound that models the string vibration The model can be approximately tuned to a frequency f by picking D such that D fy f There are ways to fine tune but we do not consider them in this simple experiment The Karplus Strong model assumes a simple averaging FIR filter for the lowpass feedback filter as given by Eq 8 2 40 of the text 1 Here we take the transfer function to be G z bo 1 271 with some bo lt 0 5 to improve the stability of the closed loop system See text ref erences 108 111 for more discussion on such models The following program gui tar dsp implements the algorithm The code is identical to that of lowpass dsp guitar dsp Karplus Strong string algorithm Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Fig 8 2 21 and Eq 8 2 40 of Introduction to Signal Processing The filtering algorithm is similar to that of lowpass reverb with the coefficient choices a 0 bO b1 0 5 The length of the delay line is designed by tuning it to a desired frequency i e D fs fl The buffer is filled with D 1 noise samples and the filter is run with
83. cases the input x must also be scaled down by an appropriate scale factor of the form Gx 2 After filtering the output may be scaled back up by the same factor as shown in the block diagram The input scaling is not im plemented in the above sample processing algorithm If necessary it may be done outside ccan using the shifter In the main program the denominator and numerator coefficients a and b must be concatenated into a double length circular buffer If the DAG pointer i4 is set to point to the beginning of a and i2 to the state vector s then after the first call of dot 12 will wrap around completely and 74 will be left pointing to the beginning of b Only after the second call of dot will the pointer 14 wrap around to the beginning of a while 12 will wrap around again Thus upon exit from ccan 14 will remain unchanged whereas 12 will be backshifted due to the last call of cdel ay 5 MACROS 105 5 8 cdir The macro cdir implements the direct form I realization and is the assembly code equivalent of the routines dir c and dir2 c of the text It takes its input from a data register returns its output into ar and updates the delay lines cdir dsp direct form I IIR filter of order M using circular buffers Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on dir c and dir2 c of Introduction to Signal Processing 0 filter order M 1 pointer to filter taps buffer in PM e g 14 2 m register to
84. d output arrays x y as each instruction is executed and as each input Const ea 0 scaling exponent for a sample gets processed const eb 0 scaling exponent for b const ex 0 pre post scaling exponent jump start nop nop nop Interupt vector table 5 Macros rti nop nop nop No interrupts used rti nop nop nop In this section we give the source code of the following macros used in the experi rti nop nop nop i ments rti nop nop nop Pen Hop END zero dsp p p p tap dsp start i2 Aw L2 w y delay line buffer tapin dsp i3 Av L3 v x delay line buffer y asp F E e E dot dsp i4 Ax m4 1 L4 0 input samples fir d i5 Ay m5 1 L5 0 output samples ETR i7 a L7 2 M 1 double length a b coef a p ae cdir dsp ficient buffer d zero i2 m2 L2 clear y delay line mavgen esp zero i3 m3 L3 clear x delay line The files are in the directory c adi_dsp macros cntr L do outputs until ce srl dm i4 m4 read input x 5 MACROS 98 5 1 Zero The macro zero initializes a circular delay line buffer to zero zero dsp initialize delay line buffer to zero Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 0 pointer to delay line buffer e g 12 1 M register to use with buffer e g M2 2 length of buffer e g L2 typical usage i2 cycles back to its initial value cntr L2 m2 1 do loop until ce loop dm i
85. dm N axl save N in DM on a music CD than on your speech 15 As L5 s m5 1 flow rate sampling pulse train c For the program dnsamp2 dsp the sampling rate is fs 8 kHz and the fre 16 Asine L6 sine m6 c sine wavetable with increment c i 2 g quency of the generated sinusoid f 1 kHz If the sampling rate is decimated zero i5 m5 L5 initialize pulse train s n to zero down by a factor of M 10 to the new sampling frequency of fg 800 Hz ax0 Ox7f ff set s 0 1 then the frequency f 1 kHz will be aliased with fg 1000 800 200 Hz dm s ax0 s 1 0 0 0 one and M 1 zeros which lies in the new Nyquist interval 400 400 Hz init sine lt sinetbl hex gt load sinusoidal wavetable To hear this effect first you must generate the 2000 long period of the wavetable from file sinetbl hex The program reads the sinusoidal table values in 1 15 hex format from the file A tal ete PN eh si netb1 hex These values can be generated by the following DOS command which pipes the output of sinetb exe into dec2hex exe wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here sinetbl 0 1 2000 dec2hex 1 15 gt sinetb1 hex input_samples ena sec_reg enable secondary register set sample processing algorithm The program plays the output for 4 seconds No microphone input is required The codec keeps sampli
86. dsp from Analog Devices FTP site and the sample talkthru program of the EZ KIT Lite Reference Manual define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 0xc855 18 9 const fs 0xc85b 0xc856 32 0xc857 22 05 0xc859 37 8 0xc85b 44 1 Oxc85c 48 Oxc85d 33 075 0xc85e 9 6 Oxc85f 6 615 ee ea ee eos include lt c adi_dsp macros begin dsp gt initializations and DSP macros start processing input samples wait for interrupt and loop forever interrupt service routine starts here enable secondary register set wait idle jump wait input_samples ena sec_reg 4 EXPERIMENTS 17 read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample write output samples to codec dm tx_buf 1 axl dm tx_buf 2 mx1 left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup It is the same as the example talkthru program of the EZ KIT Lite Reference Manual 2 The input samples from the codec are deposited in the receive buffer locations in DM rx_buf 1 and rx_buf 2 and then c
87. ead x into AX0 output in MR1 output y input off transients read x 0 into AX0 output in MR1 output y The next two programs illustrate IIR filtering based on Example 7 5 4 of the text 1 The transfer function is taken to be 0 25 0 25z7 0 50z7 Be 1 z 3 where the b coefficients have been scaled down by 4 to fit into the 1 15 format Similarly the input has been scaled down by 8 x 5 1 3 2 5 4 6 0 0 0 The expected output from that example was worked out in the text En 1 4 7 14 17 27 28 32 y 29 27 The program canex1 dsp implements an IIR filter using the canonical realization macro ccan canexl dsp canonical realization example usi ng ccan Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Example 7 5 4 of Introduction to Signal Processing The filter coefficients are 1 0 0 1 a b 1 1 2 0 4 0 25 0 25 0 50 0 The coefficients define a double length concatenated circular buffer i7 and are stored in the files a dec a hex and b output signals are in the files xiir dec xiir x 0 125 0x1000 0 375 0x3000 1 8 y 0 03125 3 8 0 12500 dec b hex The input and hex yiir dec yiir hex 0x0400 1 32 0x1000 4 32 4 EXPERIMENTS 0 250 0x2000 2 8 0 21875 0x1c00 7 32 0 625 0x5000 5 8 0 43750 0x3800 14 32 0 500 0x4000 4 8 0 53125 0x4400 17 32 0 750 0x6000 6 8
88. erial ports which allows the samples from the stereo codec s analog input to be written to DM memory at a predefined receive buffer location called rx_buf Samples from the left and right channels are stored in rx_buf 1 and rx_buf 2 After both stereo samples have been written to DM a receive interrupt is issued to the DSP which then initiates an interrupt service routine that implements the DSP sample processing algorithm to be applied to the input samples The sampling rate fs selected through the codec s format register determines the rate at which these interrupts are being issued to the DSP and therefore the rate at which the sample processing algorithm is repeatedly executed generating the output samples The processed left right output samples are then written back to some prede fined transmit buffer location in DM called tx_buf from where they are passed on to the DSP s serial port and on to the codec to be converted to analog output The overall sequence of operations is shown in Fig 3 1 ADSP 2181 DSP sample x rx buf lt 4 m analog input processing y codec algorithm tx buf gt m gt analog output Fig 3 1 Sample by sample processing on the EZ KIT Lite board For our simple example we start with the variable declarations and initializations const a 0x6000 a 0 75 const b 0x2000 b 0 25 var dm wl filter s internal state ax0 0 dm wl
89. ers const AO 0x4000 AO 0 5 input scale factor filter order y delay line buffer in DM x delay line buffer in DM concatenated coeffs in PM const M 2 var dm circ w M 1 var dm circ v M 1 var pm circ a M 1 b M 1 const ea const eb const ex 0 Ls scaling exponent for a abe scaling exponent for b input scaling exponent i2 Aw L2 w y delay line pointer 13 Av L3 v x delay line pointer 14 Aa L4 2 M 1 double length a b coefficients zero i2 m2 L2 zero i3 m3 L3 clear y delay line clear x delay line wavetable s min freq fs Ds 10 Hz square wavetable const Ds 800 var dm circ s Ds 16 As L6 s wavetable pointer and length const c 80 square wave freq f1 c fs Ds const A 0x1000 A A0 4 square wave amplitude load wavetable denominator coefficients numerator coefficients init s lt squartbl hex gt init a lt a hex gt init b lt b hex gt start processing input samples wait idle jump wait wait for interrupt and loop forever 4 EXPERIMENTS interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 mx1 dm rx_buf 2 left input sample right input sample
90. esigned with parmeq m of Appendix D with the MATLAB commands GB 1 sqrt 2 f1 800 f3 2400 fs 8000 Df 50 b1 al betal parmeq 1 0 GB 2 pi f1 fs 2 pi Df fs b3 a3 beta3 parmeq 1 0 GB 2 pi f3 fs 2 pi Df fs a13 conv al a3 b13 conv b1 b3 define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 a ee eee include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers Cconst AO 0x4000 AO 0 5 input scale factor const M 4 filter order var dm circ w M 1 circular delay line buffer in DM var pm circ a M 1 b M 1 concatenated coeffs in PM const ea 0 scaling exponent for a const eb 0 scaling exponent for b const ex 3 input scaling exponent i2 Aw L2 w delay line buffer pointer and length 14 Aa L4 2 M 1 double length a b coefficients zero i2 m2 L2 clear delay line Cconst Ds 800 wavetable s min freq fs Ds 10 Hz var dm circ s Ds square wavetable 16 As L6 s wavetable pointer and length 4 EXPERIMENTS 79 const c 80 square wave frequency f1 c
91. f the routines ccan c and can2 c of the text It takes its input from a data register returns its output into sr1 and updates the delay line ccan dsp canonical form IIR filter of order M using circular buffers Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on ccan c and can2 c of Introduction to Signal Processing 0 filter order M 1 pointer to filter taps buffer in PM e g 14 2 m register to use with tap buffer e g m4 3 pointer to delay line buffer in DM e g 12 4 m register to use with delay buffer e g m2 5 exponent for a coefficient scale factor 6 exponent for b coefficient scale factor 7 data register holding input e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri sr0 srl The filter output is returned in SR1 The input may need to be scaled down further to avoid overflows Upon exit the delay line pointer 12 is decremented The filter coefficients must be stored consecutively in the order a0 al a2 aM b0 b1 bM and i4 is points to this double length buffer The a b coefficients used in the program are related to the true a b coefficients by the scale factors defined by the exponents ea eb a_true Ga Ga 2Aea scale factor b_true Gb Gb 2Aeb scale factor a b because a0_true 1 it follows that a0 1 Ga This coefficient is redundant and not really used in the computation it always gets multiplied by zero The common
92. he MAC ALU and shifter registers that we will be using in our examples are the following mx0 mx1 my0 my1 mr mrO mrl mr2 MAC ax0 axl ay0 ayl ar ALU sr srO srl si se shifter The wordlength of these registers is as follows 16 bits mx0 mx1 my0 my1 mrO mri ax0 axl ay0 ayl ar sr0 srl si 40 bits mr consists of mr2 mri mr0 32 bits sr consists of srl sr0 8 bits mr2 se The 40 bit accumulator register mr of the MAC consists of the three registers mroO mri mr2 The result of multiplying two 16 bit numbers is a 32 bit number placed in the registers mr1 mrO where mr1 contains the 16 MSB bits and mrO the 16 LSB bits The 8 bit register mr2 is used for overflow bits The subset of MAC operations that we will be using is mr 0 clear MAC accumulator mr x y ss multiply with 32 bit precision mr x y rnd multiply round to 16 bits and put result in mr1 mr mr x y ss multiply accumulate with 32 bit precision mr mr x y rnd multiply accumulate and round to 16 bits mr mr x y ss mr mr x y rnd if mv sat mr saturate if overflow occurs where x and y may be one of the following registers x mx0 mx1 mrO mr1 mr2 ar srO srl y my0 myl Note that x must always be written to the left of y The ss qualifier treats the operands as signed 1 15 numbers and the MAC operation is carried out to full double precision The qualifier rnd cau
93. he square wave recompile and run Listen to the impulse response of the filter by lightly tapping the mike on the table Can you explain what you are hearing c Generate a square wave with frequency of 1000 Hz corresponding to wavetable increment c 100 Repeat part a Now the interference harmonics do not coincide with the filter s notches and you will still hear the interference d Design the correct multi notch filter that should be used in part b Edit the program notch dsp to reflect the new design and run it to verify that it does indeed remove the 1000 Hz interference Single and Double Notch Filters Using a single notch filter with notch frequency at f 800 Hz instead of the multi notch filter would not be sufficient to cancel completely the square wave in terference The third and higher harmonics will survive it Such a single notch filter can be designed with Eqs 8 2 22 and 8 2 23 of the text which are implemented by the MATLAB function parmeq m Assuming the same width Af 50 Hz the transfer function will be 0 980741 1 586872z7 0 980741z 1 1 586872z 0 961481z 2 A similar design with a notch at f3 3f 2400 Hz gives 0 980741 0 606131z7 0 980741z 2 1 0 606131z 0 961481z 2 The cascade of the two is a fourth order filter of the form H 3 z H z H3 z with coefficients obtained by convolving the coefficients of filter 1 and filter 3 0 961852 1 Z7 z7 z73 z74
94. i2 These steps have been put into a macro tap dsp with usage 3 INSTRUCTION SET TUTORIAL 11 tap i2 m2 d mr1 where d is in the range d 0 1 D and mr1 can be replaced by any other 16 bit computational register Fig 3 3 illustrates these operations One caveat on the use of tap is that it cannot be used as described when the delay d is variable and is passed through a register because we cannot set m2 dreg See Section 4 16 for further discussion of this point and a remedy DM Wo i i2 E gt So circular DAG1 oF la buffer 12 4 S jl w i0 mo LO a dih tap dreg il mi Ll Wp 12 m2 L2 13 m3 L3 Fig 3 3 Reading the dth tap of a circular delay line buffer In filtering operations we must put a new input sample into tap 0 before updat ing the delay line Such operation can be accomplished by m2 0 dm i2 m2 mx1 which puts the value of mx1 into the location pointed to by 12 without post modifying 12 These steps have been automated into another macro tapin dsp with usage tapin i2 m2 mx1 where the mx1 register can be replaced by any other 16 bit register Fig 3 4 illus trates this operation DM Wo f Wy i circular DAG1 12 k 5 Oth tap dreg buffer w id mo LO il mi Li Wp 12 m2 L2 7 13 m3 L3 Fig
95. i2 m2 my0 bR mr mx1 my0 ss my0 aR mr mr srl my0 ss my0 dL mr mr srO my0 rnd if mv sat mr tapin i3 m3 mr1 cdelay i3 m3 return from interrupt rti include lt c adi_dsp macros end dsp gt Lab Procedure sr0 sLL L th tap of left delay srl sRR R th tap of right delay mr1 sLL mr yL cL xL sLL left output send left output to codec mr1 sRR mr yR cR xR SRR right output send right output to codec mr bL xL mr bL xL aL sLL mr bL xL aL sLL dR SRR input to left delay update left delay mr bR xR mr bR xR aR SRR mr bR xR aR SRR dL sLL input to right delay update right delay wrapup a Go to the directory c adi_dsp examples stereo Compile and run this program Even though the self feedback multipliers were set to zero ar 4 EXPERIMENTS 55 ar 0 you will hear repeated echoes bouncing back and forth between the speakers because of the cross coupling b Next try the case dz 0 dr 0 And then dz 0 dx 0 These choices decouple the influence of one channel but not that of the other c Next introduce some self feedback such as a ar 0 5 Repeat part a 4 10 Reverberating Delay A prototypical delay effect found in most commercial audio effects processors was discussed in Problem 8 17 of the text 1
96. il wavgen i6 m6 w2 csweep ay0 ar ax0 ay0 mr 0 mrl Ox7fff sr ashift ar by 1 Chi y delay line buffer in DM x delay line buffer in DM concatenated coeffs in PM scaling exponent for a scaling exponent for b input scaling exponent y delay line pointer x delay line pointer double length a b coefficients clear y delay line clear x delay line wavetable s min freq fs Ds 2 Hz cosinusoidal wavwetab e points to sweep frequency fsweep 10 Hz w1 0 125 pi gt f1 w2 0 075 pi gt f2 500 Hz 300 Hz b0 0 9695 scaled by 2 b11 2 b0 1 9390 scaled by 2 a2 2 b0 1 0 9390 scaled by 2 a0 1 scaled by 2 load wavetable initial denominator coefficients initial numerator coefficients wait for interrupt and loop forever interrupt service routine starts here enable secondary register set left input sample right input sample ay0 w2 sine sweep n ar w0 wl w2 sin wsweep n calculate cos w0 mr 1 sr1 w0 2 4 EXPERIMENTS 84 myO ar my0 w0 mr mr sri my0 rnd mr1 cos w0 1 w0A2 2 my0 b11 current al and b1 coefficients mr ar my0 rnd mr1 2 bO cos w0 m5 1 modify i4 m5 pm i4 m5 srl start from a0 point to al save current al point to a2 m5 2 modify i4 m5 pm i4 m5 srl point to b1 save b1 point back to a0 srl
97. ing algorithm using a circular delay line buffer is given by Eq 8 2 14 The plain reverberator is an IIR comb filter with frequency response shown in Fig of Ref 1 8 2 7 When the filter parameter ais positive and near unity the peak gains 1 1 a become large causing overflows In such cases the input must be appropriately a a for each input sample x do scaled down using the shifter before it is passed to the filter This was not done in x E l UI Sp tap D w p D the above programs but the reader should be aware that it may need to be done 7 y So xta D z y aSo Sp Lab Procedure Sp p So a Go to directory c adi_dsp examples plain compile link and run the pro cdelay D w amp p gram plain dsp with the parameter values D 3000 and a 0 5 Listen to the impulse response of the system Speak into the mike The program allpass dspis the translation to assembly code If you have a portable CD with you change the jumpers on the EZ KIT Lite tallpass dsp allpass reverb canonical realization board and play a CD through it To get better sound quality you may want Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 to use the stereo version plain2 dsp In this case you may also want to Based on allpass c of Introduction to Signal Processing experiment with using different values of the left and right delays Sample processing algorithm from Eq 8 2 30 a
98. ing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only mr 0 mrl mx1 mr x input myO a tap i2 m2 D mx0 mr mr mxO myO rnd mx0 sD D th tap mr sO x a sD tapin i2 m2 mr1 cdelay i2 m2 put sO in tap O update delay mr mri my0 rnd mr a sO ayO mx0 fay0 sD ar ay0 mr1 ar y sD a sO write output samples to codec dm tx_buf 1 ar dm tx_buf 2 ar left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The program allpass2 dsp is the implementation in stereo allpass2 dsp allpass reverb in stereo Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on allpass c of Introduction to Signal Processing Sample processing algorithm from Eq 8 2 30 and Fig 8 2 17 for each x do 4 EXPERIMENTS 43 sD tap D w p D get D th tap sO x a sD in
99. into w hex and run The program disables the inputs and simply outputs the re circulating and gradually decaying random num bers b Repeat by copying w220hz hex into w hex and editing the value D 200 into the program The note you hear should be an octave lower 4 14 Wavetable Generators Here we present some examples of wavetable generators using the macro wav gen dsp Two wavetables can be used in combination to illustrate AM and FM modulation Sinusoidal Wavetable The first program sine dsp generates a simple sinusoid sine dsp sinusoid generated from a wavetable Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Sec 8 1 3 of Introduction to Signal Processing choose sampling rate in kHz 4 EXPERIMENTS 65 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 f0xc85e 9 6 Oxc85f 6 615 o y include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const D 4000 var dm circ sine D min frequency f1 fs D 8 4 2 Hz init sine lt sinetbl hex gt load one period of the wavetable generated by sinetb1 cj const A Ox7f FF A 1 signal amplitude const c 100
100. ion of downsampling effects may be found in Section 12 5 of the text 1 4 EXPERIMENTS 21 In the above program instead of actually multiplying by s n we store one period of s n into a circular buffer s that is we store the numbers 1 0 0 0 and periodically cycle over them with the help of the DAG pointer 15 with m5 1 Every M samples we encounter a nonzero value in s and then we output that input sample to the codec Otherwise we output zero to the codec The following three instructions implement this logic ar dm i5 m5 ar pass ar if ne jump output The first reads the current value of s n from the circular buffer and saves it in ar The second passes ar back into ar and its only effect is to force the updating of the flag bits of the ALU and in particular the flag AZ which is AZ 1 whenever ar 0 and AZ 0 whenever ar is nonzero The third instruction tests whether ar is nonzero and if so it outputs the current sample otherwise it outputs zeros to the codec To examine these operations in more detail look at the simulator program dnsamp1 dsp in the examples subdirectory sim The following program dnsamp2 dsp is an alternative way to demonstrate aliasing It generates internally a sinusoid of frequency f using a sinusoidal wavetable generator and then it outputs every Mth sample of that sinusoid The resulting si nusoid will be heard as having frequency fa fmodf where f fs M Wavetables are discussed in
101. is Jan 1996 0 pointer to delay line buffer e g 12 1 M register to use with buffer e g M2 2 data register holding input e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri sr0 srl typical usage put value from MX1 into O th tap note i2 is not changed m2 0 dm i2 m2 mx1 macro tapin 0 1 2 1 0 dm 0 1 2 put value from dreg 2 into delay line endmacro 5 4 cdelay The macro cdelay is the assembly code equivalent of the routines cdelay c and cdelay2 c of the text and its effect is to decrement the circular pointer pointing into the delay line buffer cdelay dsp update circular delay line buffer Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on cdelay c and cdelay2 c of Introduction to Signal Processing 0 pointer to delay line buffer e g 12 1 m register to use with buffer e g m2 typical usage cdelay i2 m2 5 MACROS 100 internal operation m2 1 modify i2 m2 Ci e backshift pointer 12 macro cdelay 0 1 1 1 modify 0 1 backshift pointer endmacro 5 5 dot The macro dot employs multifunction instructions to compute the dot product of two circular buffers one residing in DM and the other in PM Itis modeled after the FIR filtering routine fir dsp found in 3 The dot product result is returned in mr1 The I register circular pointers do not change they cycle completely around to thei
102. is c adi_dsp The various batch files DOS utilities and DSP macros for this lab are in the subdirectory macros The various examples are in the subdirectory examples The detailed contents of these directories are listed below c adi_dsp macros ezk bat ezl bat ezs bat mkezk bat dec2hex exe hex2dec exe sinetbl exe squartbl exe trapztbl exe uran exe dec2hex c hex2dec c sinetbl c squartb1 c trapztbl c uran c begin dsp ccan dsp cdelay dsp cdir dsp cfir dsp dot dsp dspmac dsp end dsp tap dsp tapin dsp wavgen dsp zero dsp template dsp c adi_dsp examples allpass comb delay fir flanger guitar lowpass multidel multitap notch plain quantize revdel reverb sim stereo wavtable 3 Instruction Set Tutorial The ADSP 2181 processor has a powerful instruction set which is summarized in the Quick Programmer s Reference section of the EZ KIT Lite Reference Manual 2 3 INSTRUCTION SET TUTORIAL 6 However to get started writing simple filtering signal processing algorithms one needs only a small subset of the full set Temporary variables such as delay line buffers and multiplier coefficients can be stored in data memory DM or program memory PM from where they can be transferred back and forth to the processor s computational units where all the arithmetic operations are carried out 3 1 Computational Units The three computational units are the multiplier accumulator MAC the arithmetic logic unit ALU and the shifter T
103. ith the filter on Do you hear the partial suppression of the interference Next replace the square wavetable with a sinusoidal wavetable generated by the DOS command sinetb 0 1 800 dec2hex 1 15 gt sinetbl1 hex 4 EXPERIMENTS 80 and replace squartb1 hex by sinetb1 hex Now the interference is one sinusoid at 800 Hz and therefore it will be completely canceled by the filter b Run the program notch2 dsp Repeat by choosing the smaller values of the input scaling exponent ex 3 2 1 0 Listen to the overflow effects c Can you explain theoretically why in the numerator of H13 Zz you have the polynomial with alternating coefficients 1 z Z7 z 3 z 4 d Run the program notch13 dsp using the wavetable squartb1 hex Listen to the suppression of the harmonics at f and f3 However the harmonic fs 4000 Hz i e the Nyquist frequency can still be heard Next replace squartb1 hex with squartb2 hex You will hear no interfer ence at all because your square wave now has harmonics only at f and f3 which are canceled by the double notch filter 4 16 Flangers and Phasers Flangers and phasers are similar audio effects involving variable notch filters The flanger is implemented as an FIR comb filter with a time variable delay The phaser is implemented as a single notch second order IIR filter with time variable notch frequency Variants of these can easily be constructed such as IIR combs with variable delays
104. l 2 All processor and codec initialization de tails have been hidden away in two include files begin dsp and end dsp simpli fying the structure of the programs and allowing the students to concentrate on the translation of their sample processing algorithm to assembly code Several reference resources are available Besides the EZ KIT Reference Manual and Data Sheets included in the kits the following reference books may be obtained in PDF format from the Analog Devices web page www analog com 1 ADSP 2100 Family User s Manual also included in the newest kits 2 DSP Applications Using the ADSP 2100 Family vols 1 amp 2 2 Getting Started 2 1 Running DSP Programs The process of running a signal processing algorithm on the ADSP 2181 chip of the EZ KIT Lite board consists of three stages 1 Creating a text source file containing the assembly code implementation of the algorithm The default filename extension is dsp The DOS edit or emacs text editors may be used to edit the source file They can be invoked by the DOS commands 2 GETTING STARTED 2 edit filename dsp emacs filename dsp 2 Compiling and linking the source file using the assembler and linker programs asm21 exe and 1d21 exe These operations have been automated into the DOS batch file ezk bat which can be invoked as follows ezk filename where the source is filename dsp The result of these operations is the executable file fi lename exe This
105. lowing program stereo dsp is an implementation 4 EXPERIMENTS 53 stereo dsp stereo delay effects with cross feedback Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Fig 8 4 1 of Introduction to Signal Processing Assuming the feedback filters are plain multipliers GL z aL GR z aR the sample processing algorithm is for each pair xL xR do sLL tap L wL pL L sRR tap R wR pR R yL cL xL sLL yR CR xR SRR oL bL xL aL SLL dR SRR oR bR xR aR SRR dL sLL cdelay L wL amp pL cdelay R wR amp pR L th tap of left delay R th tap of right delay left output right output input to left delay input to right delay update left delay update right delay define sampling rate in kHz 0xc850 8 Oxc851 5 5125 0xc852 16 0xc853 11 025 0xc854 27 42857 0xc855 18 9 32 0xc857 const fs 0xc850 0xc856 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 f0xc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const aL 0x0000 aL 0 left self feedback const aR 0x0000 aR 0 right self feedback const bL 0x6666 bL 0 8 left delay gain const bR 0x6666 bR 0 8 right delay gain const c
106. mples The next two simulator examples illustrate linear and circular delay line buffers and are based on Example 4 2 1 of the text 1 The input and 3 fold delayed output signals are x ll 1 1 2 1 2 2 1 1 I Ble y 10 0 0 1 1 2 1 2 2 1 1 They have been scaled by 4 to fit into the 1 15 format The corresponding 1 15 hex input samples are 4 EXPERIMENTS 88 4 EXPERIMENTS 89 x 0x2000 0x2000 0x4000 0x2000 0x4000 0x4000 0x2000 0x2000 update linear buffer myO dm w 2 w 2 tap 2 dm w 3 my0 w 3 w 2 Linear Buffer my0 dm w 1 w 1 tap 1 The program delex1 dsp implements the 3 fold delay using a linear buffer dm w 2 my0 w 2 w 1 delex1 dsp delay example using linear buffer my0 dm w w 0 tap 0 Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 transients dm w 1 my0 w 1 w 0 Based on Example 4 2 1 of Introduction to Signal Processing idle include lt c adi_dsp macros dspmac dsp gt DSP macros endmod module ram abs 0 delex1 Circular Buffer var dm x 8 input samples var dm y 11 output samples The program delex2 dsp implements the 3 fold delay using a circular buffer var dm w 4 linear delay line buffer in DM delex2 dsp delay example using circular buffer init x lt xfir hex gt Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 init w 0x0000 0x0000 0x0000 0x0000 Based on Example 4 2 1 of Introducti
107. n include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const FS 8000 sampling rate in samples sec 4 EXPERIMENTS 30 const M 206 var dm circ w M 1 var pm circ h M 1 from firlp m with fc 200 Hz Df 100 Hz circular delay line buffer in DM filter coefficient buffer in PM const D 800 var dm circ s D basic frequency increment fs D 10 Hz sinusoidal wavetable from sinetbl hex see Section 8 1 3 of text const cl 10 f1 c1 fs D c1 10 100 Hz const c2 40 f2 c2 fs D c2 10 400 Hz Cconst Al 0x4000 A1 0 5 amplitude of sinusoid 1 const A2 0x4000 A2 0 5 amplitude of sinusoid 2 const T 4 desired total duration in seconds var dm N N fs T no of samples in T sec axl T FS N T FS duration in samples dm N axl save N in DM i2 Aw L2 w i4 Ah L4 delay line buffer pointer and length h coefficient buffer pointer and length 15 As L5 s m5 cl 16 As L6 s m6 c2 sinusoid f1 wavetable increment c1 sinusoid f2 wavetable increment c2 zero i2 m2 L2 clear delay line read coefficients in 1 15 hex format from file fir hex load sinusoidal wavetable from file sinetb hex init h lt fir hex gt init s lt sinetbl hex gt start processing input samples
108. n Eq 8 2 8 of Introduction to Signal Processing I O equation y n a0 x n al x n D a2 x n 2D a3 x n 3D Sample processing algorithm for each x do sl tap 4 D w p D s4 tap 4 D w p 4 D p s0 x a sl y sO a4 s4 cdelay 4 D w amp p get tap D get tap 4D filter output update delay define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a0 0x7fff a0 0 9999 approximate unity const al 0x4000 fal 0 50 const a4 0x0800 a4 alA4 0 5044 0 0625 const D 1600 TD D fs 1600 8000 0 20 sec var dm circ w 4 D 1 delay line buffer max delay 4 D i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable seconda
109. n multipliers G1 z al G2 z a2 and circular buffers for the two delays the sample processing algorithm is for each x do s1D tap D1 wl p1 D1 D1 th tap output s2D tap D2 w2 p2 D2 D2 th tap output 4 EXPERIMENTS 58 4 EXPERIMENTS 59 y bO x b1 s1D b2 s2D filter output mr mr srO my0 ss mr bO x b1 s1D p2 s20 s1D a2 s2D put input s20 into delay 2 cdelay D2 w2 amp p2 update delay 2 my0 b2 pl s10 x al s1D put input s10 into delay 1 mr mr srl my0 rnd mr y bO x b1 s1D b2 s2D cdelay D1 w1 amp p1 update delay 1 if mv sat mr write output samples to codec define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 dm tx_buf 1 mr1 left output sample 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 dm tx_buf 2 mrl right output sample Cconst fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 sample processing algorithm cont d Oxc85e 9 6 Oxc85f 6 615 o mr 0 mr1 sr0 mr s1D include lt c adi_dsp macros begin dsp gt initializations and DSP macros myO a2 mr mr srl my0 rnd mr s20 s1D a2 s2D define constants variables and buffers if mv sat mr tapin i
110. nclude lt stdio h gt A E include lt math h gt if isdigit c return c 70 hex digits 0 9 void main int argc char argv else return c a 10 hex digits a f int i D D1 double A1 A2 x if argc 6 6 2 Wavetable Generators puts nSquare Wavetable R puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n The waveform generator programs below are based on those given in Section 8 1 3 puts Usage squartbl Al A2 D1 D t gt file dat n of the text 1 They all generate one period of a required waveform to be stored puts Al amplitude of sub period D1 6 APPENDIX 112 puts A2 amplitude of remaining period D D1 puts D1 sub period puts D total period puts t 1 alternates discontinuously from Al to A2 puts t 0 goes through mid level value A1 A2 2 exit 0 3 Al atof argv 1 A2 atof argv 2 D1 atoi argv 3 atoi argv 4 x 1 atof argv 5 x 1 t o ll printf 151f n Al x Al A2 2 A1 or A1 A2 2 for i 1 i lt Dl i printf 151f n A1 printf 151f n A2 x Al A2 2 A2 or A1 A2 2 for i D1 1 i lt D i printf 151f n A2 The program trapztbl c implements a trapezoidal waveform generator which also includes a triangular waveform as a special case trapztbl c trapezoidal wavetable of period D and subperiods D1 D2 Junior DSP Lab
111. nd Fig 8 2 17 for each x do b Recompile and run the program with the new feedback coefficient a 0 25 sD tap D w p D get D th tap Listen to the impulse response Repeat for a 0 75 Discuss the effect of sO x a sD input to delay Tine d A y a s0 sD filter output increasing or decreasing a p s0 but input to delay tine ET celay D w amp p update delay line c According to Eq 8 2 16 the effective reverberation time constant is given by lne define sampling rate in kHz Tet pai SoS DE D fs 0xc850 8 Oxc851 5 5125 0xc852 16 na 0xc853 11 025 0xc854 27 42857 0xc855 18 9 const fs 0xc850 0xc856 32 0xc857 22 05 0xc859 37 8 For each of the above values of a calculate Teff in seconds assuming 0xc85b 44 1 Oxc85c 48 Oxc85d 33 075 0 001 which corresponds to the so called 60 dB time constant Is what you i 0xc85e 9 6 0xc85f 6 615 hear consistent with this expression 4 EXPERIMENTS 42 include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a 0x4000 const D 3000 var dm circ w D 1 feedback coefficient a 0 50 TD D fs 3 8 0 375 sec delay line buffer i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line start process
112. ng of w L2 0 L2 must be set to 0 for a linear buffer The post modify feature is still present except i2 does not automatically wrap around upon reaching the end of the buffer The simulator example delex1 dsp in the subdirectory examples sim illustrates the operation of a linear delay line 4 EXPERIMENTS 16 3 9 Concatenated Circular Buffers Finally we mention concatenated circular buffers which can be used to store the denominator and numerator coefficients of an IIR filter The following declaration defines two buffers each of length M 1 in PM const M 100 var pm circ a M 1 b M 1 14 Aa L4 2 M 1 This declaration defines an extended circular buffer of double length 2 M 1 The DAG pointer 14 will traverse both buffers a and b before wrapping around to the beginning of a See Section 5 7 for more details 4 Experiments 4 1 Sampling and Quantization This section contains three types of experiments a sampling and immediate play back based on the EZ KIT Lite s talkthru program b input quantization effects and c demonstration of aliasing effects by downsampling Talkthru This experiment illustrates the sampling and immediate playback of an input audio signal The following program thru dsp is simply a copy of the template program template dsp thru dsp talkthru program may be used as template Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on mic2out
113. ng the input and therefore interrupts the processor ay0 dm N at the sampling rate fs However the samples that are loaded automatically ar ay0 1 decrement N gt N 1 until zero hi a buf d 1 d the i i amen ar save nen NE into the receive register rx_buf are not used Instead the interrupt service if eq jump stop do not stop until N iterations routine reads a wavetable sample and sends it to the output every Mth time while at other times it sends zero to the output mr1 dm i6 m6 mr1 sinusoidal input sin 2 pi f t p In this experiment first choose M 1 compile and run the program to hear ar dm i5 m5 get sampling pulse the 1 kHz sinusoid Then set M 10 recompile and run to hear the 200 Hz ar pass ar forces updating of AZ flag aliased version if ne jump output if AR 0 write output mri 0 felse output is zero 4 2 Delays output The program delay dsp implements a maximum delay of duration Tp 0 75 sec dm tx_buf 1 mr1 left output sample At an 8 kHz sampling rate the total number of samples in the delay will be dm tx_buf 2 mr1 right output sample T ea D a fsTp 8000 Hz x 0 75 sec 6000 stop Thus the transfer function of the delay will be H z z z76000_ Its implemen tation requires a 1 dimensional circular buffer include lt c adi_dsp macros end dsp gt wrapup q 600 delay dsp plain delay by TD sec Lab Procedure Junior DSP Lab R
114. nidis Jan 1996 choose sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs Oxc85c 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 onan nnn nnn nn nnn nnn nnn nnn nnn nnn nnn include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const M 6 decimation ratio fs_low fs M var dm circ s M low rate sampling pulse train Cconst A Ox7fff A 1 amplitude of sampling pulse i5 As L5 s m5 1 low rate sampling pulse train cntr M initialize pulse train to zero do zero_s until ce s 0 0 0 zero_s dm i5 m5 0 may also call zero i5 m5 L5 ax0 A set s 0 A dm s ax0 s A 0 0 A and M 1 zeros start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec 4 EXPERIMENTS 20 mrO dm rx_buf 1 left input sample mr1 dm rx_buf 2 right input sample sample processing algorithm
115. nscaled coefficients are related by f 1 1 1 a ao a3 4m 1 ar eae g a 1 1 1 1 1 b bo bj bm Gp bo bi bml Gb where a are the scaled coefficients that will be loaded in DM and a are the true coefficients Note that ao is no longer unity but that does not matter because it is not really used in the computation The overall transfer function is not affected by these scale factors only the intermediate calculations 5 MACROS 104 x UG UG MAN a bo pels So G gt y z l Xy So Ww l l a Z Wot bf y 17 by S2 Fig 5 1 Canonical form with scaling factors To be able to use the dot product macro dot we write the sample processing algorithm for the true coefficients in the form of Eq 7 2 6 of the text which we have modified here to use a circular delay line buffer w with state vector s defined relative to the buffer pointer p for each input sample x do xp So 0 xp So X dot M a s y dot M b s cdelay M w amp p Writing the unscaled coefficients in terms of the scaled ones a Gga and b Gpb we obtain the sample processing algorithm depicted in the above block diagram for each input sample x do xp So 0 xp So X Gadot M a s y Gpdot M b s cdelay M w amp p The canonical realization is more prone to overflows than the direct or trans posed forms In such
116. of Chapter 10 of the text 1 firlp m lowpass FIR design 4 EXPERIMENTS 27 Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 the filter coeff file lp dec in decimal format must be postprocessed by dec2hex to convert it to the 1 15 format hex file lp hex that is dec2hex 1 15 lt Ip dec gt lp hex to run it on the EZ KIT Lite copy lp hex into fir hex recompile and load fir dsp you may also need to edit the designed filter order M into fir dsp fs 8000 8 kHz rate Apass 0 1 0 1 dB Astop 40 40 dB stopband ripple delta 0 01 fc input cutoff frequency fc in Hz e g fc 200 Hz Df input transition width Df in Hz e g Df 100 Hz fpass fc Df 2 fstop fc Df 2 h kih 1 fs fpass fstop Apass Astop Kaiser design save lp dec h ascii save in decimal format N N1 size h M N 1 filter order M NF 400 number of frequencies O NF 1 pi NF NF fregs over positive Nyquist 20 logl0 abs dtft h w magnitude response in dB w H save lpmag dat H ascii Using this program we have designed two FIR filters with a sampling rate of 8 kHz and cutoff frequencies and widths fo af 200 Hz 100 Hz 200 Hz 10 Hz These specifications imply that the passband transition and stopband frequency ranges are in Hz where the stopband extends to the Nyquist frequency f 2 4000 Hz
117. on to Signal Processing jump start nop nop nop Interupt vector table rti nop nop nop No interrupts used include lt c adi_dsp macros dspmac dsp gt DSP macros rti nop nop nop rti nop nop nop module ram abs 0 delex1 rti nop nop nop rti nop nop nop var dm x 8 input samples rti nop nop nop var dm y 11 output samples var dm circ w 4 circular delay line buffer in DM start i3 Ax m3 1 L3 0 input samples i5 Ay m5 1 L5 0 output samples init x lt xfir hex gt init w 0x0000 0x0000 0x0000 0x0000 cntr 8 do outputs until ce process 8 input samples jump start nop nop nop Interupt vector table myl dm w 3 get tap 3 rti nop nop nop No interrupts used dmci5 m5 myl save in y and point to next y rti nop nop nop rti nop nop nop mx1 dm i3 m3 read x and point to next x rti nop nop nop dm w mx1 put x in delay line rti nop nop nop update linear buffer rti nop nop nop myO dm w 2 w 2 tap 2 dm w 3 my0 w 3 w 2 start i2 Aw L2 w circular buffer i3 Ax m3 1 L3 0 input samples myO dm w 1 w 1 tap 1 i5 Ay m5 1 L5 0 output samples dm w 2 my0 w 2 w 1 cntr 8 my0 dm w w 0 tap 0 do outputs until ce process 8 input samples outputs dm w 1 my0 w 1 w 0 m2 3 modify i2 m2 point to tap 3 m2 0 my1 dm i2 m2 get tap 3 cntr
118. ope frequency is chosen to be 2 Hz and the signal frequency 200 Hz The AM modulated signal is of the form x t A t sin 27ft where A t Aenvsin 2TTfenvt A common sinusoidal wavetable sinetb1 hex is used to generate both the signal and its sinusoidal envelope fam dsp AM modulation of using common wavetable Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Sec 8 1 3 of Introduction to Signal Processing choose sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 nanan nnn nnn nnn nnn nnn nnn nnn nnn nnn include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const D 4000 var dm circ sine D min frequency f1 fs D 8 4 2 Hz load one period of the wavetable generated by sinetb1 cj Aenv 1 envelope amplitude envelope fenv cenv f1 2 Hz init sine lt sinetbl hex gt const Aenv Ox7fff const cenv 1 15 Asine L5 sine pointer for envelope generator const c 100 signal frequency f c f1 200 Hz 16 Asine L6 sine pointer for signal generator start processing input samples
119. opied into the registers ax1 and mx1 for the left and right channels Then without any further processing the input samples are written back into the transmit buffer locations tx_buf 1 and tx_buf 2 from where they are read by the codec and sent to the analog output Lab Procedure Change directory into c adi_dsp examples quantize by the DOS commands dsp cd quantize Compile link and load this program with the DOS commands ezk thru ezl thru Speak into the mike Quantization Effects The program quantize dsp illustrates input quantization effects quantize dsp quantization to B bits Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 choose sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs Oxc85b 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 include lt c adi_dsp macros begin dsp gt initializations and DSP macros 4 EXPERIMENTS 18 define constants variables and buffers Cconst B 6 quantization bits per sample const L 16 B L least significant bits thrown away start processing input samples wait idle jump wait wait
120. or direct sound const D 6000 TD D fs 6 8 0 75 sec var dm circ w D 1 delay line buffer i2 Aw L2 w buffer pointer and length zero i2 m2 L2 clear delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only F tap i2 m2 D srl sr1 sD mri srl myl c mr mr mx1 my1 rnd mr y sD c x if mv sat mr ar mrl save for output myl b mr mx1 my1 ss mr b x myl a mr mr srl my1 rnd mr sO b x a sD if mv sat mr tapin i2 m2 mr1 put sO into delay line input cdelay i2 m2 update delay write output samples to codec dm tx_buf 1 ar left output sample dm tx_buf 2 ar right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Go to the directory c adi_dsp examples revdel Compile and run this program Listen to its impulse response and speak into the mike Here
121. otal bits puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n puts Usage sinetbl c A D gt file dat n int calloc B sizeof int B bit vector puts c 0 1 for sine cosine s char calloc B 4 1 sizeof char B 4 hex digits puts A amplitude puts D period R pow 2 a 2 a full scale exit 0 while fscanf stdin s s EOF hex chars for i 0 1 lt B 4 i i th hex digit c atoi argv 1 for j 0 j lt 4 j j th bit A atof argv 2 b 4 i j c2h s i 1 lt lt 3 j 1 0 masks 8 4 2 1 D atoi argv 3 x dac b B R scaled output printf 161f n x for i 0 i lt D i if c 1 end of main printf 151f n A cos 2 pi i D else printf 151f n A sin 2 pi i D c2h c convert hex char into hex integer The program squartb1 c generates one period of length D of a square wave One input is the char 0 1 2 3 4 5 6 7 8 9 a b c d e f 3 4 6 7 8 9 output is the int 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 can choose between a a completely discontinuous jumping between two levels or E b a more gradual transition where the values at the discontinuities are replaced by the mid value between the levels ue c2h c squartbl c square wavetable of period D and subperiod D1 arg Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 c tolower c i
122. passband transition stopband 0 150 150 250 250 4000 0 195 195 205 205 4000 Thus within the passband the attenuation must remain less than 0 1 dB and within the stopband it must be greater than 40 dB The magnitude responses H f of the two filters are plotted in units of dB that is 20l0og H f in the following figures 4 EXPERIMENTS Lowpass Filter Af 100 Hz 80t 90 0 0 0 f kHz Lowpass Filter Af 10 28 Hz dB 1 80 90 00 02 04 06 08 10 1 2 f kHz The designed filters have orders M 206 and M 2054 respectively and their impulse responses are in the data files 1p1 dec and 1p2 dec in decimal format as generated by firlp m As discussed in Ch 10 of the text 1 that the filter order M of an FIR filter is essentially inversely proportional to its transition width Af and therefore it should be no surprise that the second filter has 10 times greater order than the first FIR Filtering in Stereo If we want to process the input samples in stereo we must apply the filter to the two channels separately The following program fir2 dsp independently processes the left and right stereo channels It uses two circular delay line buffers in DM and a common filter coefficient buffer in PM fir2 dsp FIR filter experiment with separate stereo channels Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on cfir c or cfir2
123. plemented in its transpose realization form which avoids overflows better than the canonical form It is depicted below together with its sample processing algorithm lt Lal gt si Y for each input x do Sb Sp tap D w p D g y Sp ax r p So X ay Eo y cdelay D w amp p DEN The program allpass3 dsp is the assembly code implementation fallpass3 dsp allpass reverb transpose realization Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on allpass c of Introduction to Signal Processing Sample processing algorithm from Eq 8 2 30 and Fig 8 2 17 for each x do sD tap D w p D sO x a sD y a s0 sD get D th tap input to delay line filter output 4 EXPERIMENTS 45 p s0 put input to delay line celay D w amp p update delay line define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const a 0x4000 feedback coefficient a 0 50 const D 3000 TD D fs 3 8 0 375 sec var dm circ w D 1
124. pointer and length zero i2 m2 L2 clear delay line init h lt fir hex gt read coefficients in 1 15 hex format from file fir hex start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 mx1 dm rx_buf 2 left input sample right input sample sample processing algorithm process right input only J cfir M 14 m4 i2 m2 mx1 input from mx1 output in mr1 write output samples to codec dm tx_buf 1 mrl dm tx_buf 2 mrl left output sample right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The filter coefficients are read from the hex file fir hex The value of the filter order M must be edited into the program The delay line buffer is in DM memory and the filter coefficient buffer in PM The following MATLAB file firlp m implements a Kaiser design of a lowpass filter with prescribed cutoff frequency and transition width The passband and stopband attenuations are assumed to be 0 1 dB and 40 dB respectively It uses the functions dtft m and k1h m
125. pt service routine starts here include lt c adi_dsp macros zero dsp gt input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample References mx1 dm rx_buf 2 right input sample 1 S J Orfanidis Introduction to Signal Processing Prentice Hall Upper Saddle sample processing algorithm River NJ 1996 example tap i2 m2 D my1 put Dth tap output of delay into MYI 2 ADSP 2100 Family EZ KIT Lite Reference Manual Analog Devices Norwood MA tapinCi2 m2 mx1 put current input from MX1 into Oth tap cdelay i2 m2 update delay 1995 Available also from www analog com ee 3 Analog Devices BBS 617 461 4258 or anonymous ftp site ftp analog com or write output samples to codec web site ww analog com The ez1d com utility is included in the file ezkfo rum zip in the subdirectory pub dsp ezktil of the ftp site dm tx_buf 1 axl left output sample dm tx_buf 2 mx1 right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The files begin dsp and end dsp in the directory c adi_dsp macros are the beginning and ending part
126. put to delay line y a s0 sD filter output p sO put input to delay line celay D w amp p update delay line define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 0xc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 f0xc85e 9 6 0xc85f 6 615 o include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const aL 0x4000 const DL 3000 left feedback coefficient aL 0 50 left TD D fs 3 8 0 375 sec const aR 0x4000 const DR 3000 right feedback coefficient aR 0 50 right TD D fs 3 8 0 375 sec var dm circ wL DL 1 var dm circ wR DR 1 left delay line buffer right delay line buffer i2 AwL L2 wL 13 AwR L3 wR left delay buffer pointer and length right delay buffer pointer and length zero i2 m2 L2 zero i3 m3 L3 clear left delay line clear right delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec
127. q 8 2 31 of 1 The program reverb dsp is an implementation reverb dsp Schroeder s reverberator Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Fig 8 2 18 of Introduction to Signal Processing Sample processing algorithm is given by Eq 8 2 31 and the code is taken from plain dsp and allpass dsp choose sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc85b 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 gt y include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers 4 EXPERIMENTS 49 const b1 Ox7fff b1 0 9999 const b2 0x7333 b2 0 90 const b3 0x6666 b3 0 80 const b4 0x599a b4 0 70 const al 0x70a4 al 0 88 const a2 0x70a4 a2 0 88 const a3 0x70a4 a3 0 88 const a4 0x70a4 a4 0 88 const a5 0x70a4 a5 0 88 const a6 0x70a4 a6 0 88 const D1 1759 const D2 1949 const D3 2113 const D4 2293 const D5 307 const D6 313 var dm circ w1 D1 var dm circ w2 D2 var dm circ w3 D3 var dm circ w4 D4 var dm circ w5 D5 var dm circ w6 D6 11 11 11 11 11 11 var dm x 5 dm
128. r candcfir2 c of the text It takes its input from a data register and puts it in tap 0 of the delay line then it computes the dot product output of the filter and returns it into mr1 and finally it updates the delay line cfir dsp direct form FIR filter of order M using circular buffers Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on cfir c and cfir2 c of Introduction to Signal Processing In book y cfir M h w amp p x 0 filter order M so that filter length is L M 1 1 pointer to filter taps buffer in PM e g 14 2 m register to use with tap buffer e g m4 3 pointer to delay line buffer in DM e g i2 4 m register to use with delay buffer e g m2 5 data register holding input e g ax0 axl ay0 ayl ar mx0 mx1 my0 my1 mri sr0 srl The filter output is returned in MR1 Upon exit the delay line pointer i2 is decremented typical usage cfir M 14 m4 12 m2 mx1 internal operation tapin i2 m2 mx1 dot M 14 m4 12 m2 cdelay i2 m2 put input from MX1 into tap 0 compute dot product output update delay line macro cfir 0 1 2 3 4 5 tapin 3 4 5 read input sample into delay line dot 0 1 2 3 4 compute filter output into MR1 cdelay 3 4 update delay line endmacro 5 MACROS 102 5 7 CCAN The macro ccan implements the canonical realization of an IIR filter and is the assembly code equivalent o
129. r entry values dot dsp dot product of a DM with a PM circular buffer of length M 1 Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 0 filter order M i e length L M 1 1 pointer to filter taps buffer in PM e g 14 not modified 2 m register to use with tap buffer e g m4 3 pointer to delay line buffer in DM e g i2 not modified 4 m register to use with delay buffer e g m2 result is returned in MR1 12 14 are not modified they cycle around to their entry values typical usage dot M 14 m4 i2 m2 internal operation m2 1 m4 1 mr 0 mxO dm i2 m2 my0 pm i4 m4 cntr M do loop until ce loop mr mr mxO myO ss mxO dm i2 m2 my0 pm i4 m4 mr mr mxO myO rnd if mv sat mr macro dot 0 1 2 3 4 local loop 2 1 4 1 mr 0 mx0 dm 3 4 my0 pm 1 2 cntr 0 do loop until ce Toop mr mr mx0 myO ss mx0 dm 3 4 my0 pm 1 2 mr mr mxO myO rnd 5 MACROS 101 if mv sat mr endmacro When dot is used in the implementation of IIR filters the DAG pointer 14 points to a double length circular buffer in PM consisting of the concatenation of the de nominator and numerator coefficients In that case it takes two calls of dot for 14 to wrap around completely See the macros ccan and cdir 5 6 cfir The macro cfi r is the assembly code equivalent of the routines cfi
130. r in struction in order to hear the desired signal plus the noise The particular square wave of period 10 generated by the program is of the form v n 1 1 1 1 1 1 1 1 1 1 It contains only odd harmonics As discussed in Example 1 4 6 and Section 9 7 of the text all harmonics that lie outside the Nyquist interval are wrapped inside the interval and get aliased with the harmonics within the interval Thus the above periodic signal contains only the harmonics w 2TT 10 W3 3w1 677 10 and Ws 5401 107 10 Tr In fact we can show using the techniques of Section 4 EXPERIMENTS 73 9 7 of the text that the signal v n can be expressed in the alternative sinusoidal form obtained from the 10 point DFT of one period of the square wave wi sin w n 5 wo Sin w3n sin sin 3 0 2 cos Ws5n v n Thus the filter only acts to remove these three odd harmonics It may appear puzzling that the Fourier series expansion of this square wave does not contain exclusively sine terms as it would in the continuous time case This discrepancy can be traced to the discontinuity of the square wave In the continuous time case any finite Fourier series sinusoidal approximation to the square wave will vanish at the discontinuity points Therefore a more appropriate discrete time square wave might be of the form v n 0 1 1 1 1 0 1 1 1 1 The DOS square wavetable generator squartb1 exe has
131. rrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only mr 0 mrl mx1 mr x input myl a tap i2 m2 D mx1 mx1 sD D th tap mr mr mx1 my1 rnd mr x a sD tapin i2 m2 mr1 put y in tap 0O cdelay i2 m2 update delay write output samples to codec dm tx_buf 1 mrl left output sample dm tx_buf 2 mrl right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup The program plain2 dsp is the implementation in stereo plain2 dsp plain reverb IIR comb filter in stereo Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 4 EXPERIMENTS 39 Based on plain c of Introduction to Signal Processing Sample processing algorithm from Eq 8 2 14 and Fig 8 2 6 for each x do sD tap D w p D get D th tap y x a sD filter output p y put y into tap 0 cdelay D w amp p update delay define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0
132. rupt service routine starts here input_samples ena sec_reg enable secondary register set sample processing algorithm wavgen i5 m5 Am cm ay1 ayl Am sin 2 pi fm t axl c0 ar axl ayi wavgen i6 m6 A ar mx1 far c c0 Am sin 2 pi fm t mx1 FM modulated sinusoid write output samples to codec dm tx_buf 1 mx1 left output sample dm tx_buf 2 mx1 right output sample return from interrupt rei include lt c adi_dsp macros end dsp gt wrapup Lab Procedure a Goto directory c adi_dsp examples wavetab1 Run the program sine dsp and listen to the 200 Hz sinusoid Reset the frequency to 50 Hz recompile and run Keep decreasing the frequency by 10 Hz each time and determine the lowest frequency you can hear but to be fair don t increase the speaker volume that would compensate the attenuation introduced by your ears b Set the frequency at 4000 Hz the Nyquist frequency Recompile and run Can you explain what you hear Replace the sinusoidal wavetable sinetb hex with a cosinusoidal one and repeat the experiment at the Nyquist frequency c Replace the sinusoidal table sinetb1 hex with the square wavetable squar tb1 hex which has period 4000 and is equal to 1 for the first half of the period and 1 for the second h
133. ry register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only mr 0 mr1 mx1 mr x input 4 EXPERIMENTS 37 mx0 a4 tap i2 m2 4 D my0 mr mr mx0 my0 rnd if mv sat mr my0 s4 4D th tap mr y sO a4 s4 saturate mr if overflow tapin i2 m2 sr0 cdelay i2 m2 put input from srO into tap 0 update delay write output samples to codec dm tx_buf 1 mri dm tx_buf 2 left output sample mri right output sample return from interrupt rti include lt c adi_dsp macros end dsp gt wrapup 4 5 Plain Reverb A plain reverberator can be used as an elementary building block for more compli cated reverberation algorithms It is given by Eq 8 2 12 of the text 1 and shown in Fig 8 2 6 Its I O equation and transfer function are y n ay n D x n H z aqz D Its sample processing algorithm using a circular delay line buffer is given by Eq 8 2 14 of Ref 1 x S gi for each input sample x do Y Sp tap D w p D z y x asp p y IO cdelay D w amp p a The following program plain dsp is the translation to
134. s var dm circ w M 1 delay line buffer in DM var pm circ a M 1 b M 1 concatenated coeffs in PM init x lt xiir hex gt input samples init a lt a hex gt denominator coefficients init b lt b hex gt numerator coefficients const ea 0 scaling exponent for a const eb 0 scaling exponent for b const ex 1 pre post scaling exponent jump start nop nop nop Interupt vector table rti nop nop nop No interrupts used rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop idle endmod ashift srl by ex hi dmci5 m5 srl L4 0 L5 0 L7 2 M 1 by ex hi 95 delay line buffer input samples output samples double length a b coef ficient buffer clear delay line read input x pre scale x down compute output y input from srl output in sri post scale y up write y Further down scaling of the input and up scaling of the output are necessary to avoid overflows The input scaling exponent was 1 The program direx1 dsp implements an IIR filter using the direct form realization macro cdir It does not need any input down scaling and therefore ex 0 direxl dsp direct form I realization example using cdir Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Example 7 5 4 of Introduction to Signal Processing The filter coefficients are a b 1 1
135. s follows hex2dec 1 15 lt data hex gt data dec For example the following column of decimal numbers fed into dec2hex 1 15 for mat produces the second column of hex numbers In turn the hex numbers fed into hex2dec 1 15 format will produce the third column of decimal numbers which are the original numbers rounded to 16 bit accuracy 1 00000 Ox7 FFF 0 999969482421875 largest positive number 0 50000 0x4000 0 500000000000000 0 40000 0x3333 0 399993896484375 0 00003 0x0001 0 000030517578125 smallest positive number 0 00003 Oxf FFF 0 000030517578125 smallest negative number 0 40000 Oxcccd 0 399993896484375 0 50000 0xc000 0 500000000000000 1 00000 0x8000 1 000000000000000 largest negative number The overall range of representable numbers depends on the format For example the above column of hex numbers fed into the hex2dec 2 14 format will produce the third column scaled up by a factor of two To determine which a b format to use recall that all numbers to be converted must lie within the format s range 271 lt x lt 291 2 b Thus for example the ranges for the 1 15 2 14 and 3 13 formats will be 1 lt x lt 1 27 2 lt x lt 2 27 4 lt x lt 4 27 2 GETTING STARTED 4 In general using B total bits so that a b B the a b format is simply a scaled up version of the standard 0 B two s complement binary representation b1 b2 bg x by 27 b227 b3273 bp2 8 0
136. s of the talkthru program in the EZ KIT Lite s Reference Manual 2 and the mic2out dsp program found in 3
137. seed double m R x if argc 5 puts Generate a block uniform random numbers puts Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 n puts Usage uran m R N iseed gt x dat n puts N length of block puts range is the interval m R m R mean m n exit 0 atof argv 1 atof argv 2 atoi argv 3 iseed atol argv 4 for i 0 i lt N i m R N x 2 R ran amp iseed 0 5 m printf 151f n x 6 3 Template and Begin End Files The file template dsp serves as the starting point of all program examples 6 APPENDIX 114 REFERENCES 115 template dsp use as template for sample processing algorithms We have made only two modifications to these files 1 we redefined the codec s Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 data format register so that it can be passed in as the constant fs which may be Based on mic2out dsp from Analog Devices FTP site and the sample talkthru selected at the beginning of every example program and 2 we added the include program of the EZ KIT Lite Reference Manual file dspmac dsp which includes all the DSP macros its listing is choose sampling rate in kHz dspmac dsp includes all DSP macros 0xc850 8 Oxc851 5 5125 Oxc852 16 Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 0xc853 11 025 0xc854
138. ses the double precision 32 bit result to be rounded off to its 16 most significant bits with the result residing in mr1 The last if mv sat mr instruction saturates mr to its largest positive or negative value whenever the overflow flag mv is raised The subset of ALU operations that we will be using is 3 INSTRUCTION SET TUTORIAL 7 ar X y ar X y ar y xX where the permissible registers for x and y are x ar ax0 axl mrO mrl mr2 srO srl y ay0 ayl The shifter instructions that we will be using are the arithmetic shifts sr ashift x by exp hi sr ashift x Chi multiply x by 2 P with MSB result in sr1 get exp from se register where x and exp are x si sr0 srl ar mrO mrl mr2 exp any signed integer such as 1 2 The effect of this instruction is to scale x by the factor 2 P and place the result in sr with sr1 containing the 16 MSB bits In the second ashift instruction the value of the exponent exp has been preloaded into the 8 bit exponent register se and is read from there 3 2 Data Transfers Any of the above 16 bit computational registers can be loaded with a numerical value in 1 15 format or transferred back and forth to another such register or to data memory DM or program memory PM For example suppose we have declared some constants and some variables in data memory DM const a 0x6000 const D 3 var dm w D 1 var dm x y a 0 75 in decimal
139. sing hex2dec into their unscaled decimal versions using the 5 11 format to compensate for the factor 16 The program firex1 dsp implements the FIR filter using the macros tapin dot and cdelay firexl dsp FIR example using tapin dot cdelay Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Example 4 2 1 of Introduction to Signal Processing The filter coefficients and are stored in the files h dec h hex The input and output signals are in the files xfir dec xfir hex yfir dec yfir hex 4 EXPERIMENTS h 0 25 1 4 x 0 25 1 4 0 50 2 4 0 25 1 4 0 25 1 4 0 50 2 4 0 25 1 4 0 25 1 4 0 50 2 4 0 50 2 4 0 25 1 4 0 25 1 4 91 0 0626 1 16 0 1875 3 16 0 1875 3 16 0 3125 5 16 0 1875 3 16 0 4375 7 16 0 2500 4 16 0 1875 3 16 0 1875 3 16 0 0000 0 16 0 0625 1 16 The h coefficients and x have been scaled down to fit in 1 15 format as compared to Example 4 2 1 include lt c adi_dsp macros dspmac dsp gt module ram abs 0 firexl const L 8 const M 3 var dm ram x L var dm ram y L M var dm ram circ w M 1 var pm ram circ h M 1 mit x lt xfir hex gt nit h lt h hex gt jump start nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop rti nop nop nop start i2 Aw m2 0 L2 w 14 h m4 0 L4 h i3 Ax m3 1 L3 0 15 A
140. so in general be scaled down before passed into cdir and then the output from cdir must be scaled up endmod xl 2A ex x input to cdirQ yl cdir x1 output from cdir due to x1 Lab Procedure y 2Aex yl output due to x Go to directory c adi_dsp examples sim Compile and load each program into In this example unlike canex1 we use ex 0 or larger the simulator by running the batch file ezs bat that is ezs quantex1l include lt c adi_dsp macros dspmac dsp gt dsp macros ezs dnsampl ezs delex1l module ram abs 0 direx1 ezs delex2 ezs firexl const L 9 input signal length ezs firex2 const M 3 filter order ezs canexl var dm x L input samples ezs direxl var dm y L output samples var dm circ w M 1 y delay line buffer in DM A E F A VaridW cites wi MeL x delay line buffer in DM Three predefined data windows will open Using the lt CTRL G gt command set the var pm circ a M 1 b M 1 concatenated coeffs in PM windows to display the contents of the arrays y x and w The windows can be toggled from hex to decimal format using lt CTRL T gt init x lt xiir hex gt input samples Step through the programs by issuing the command step in the command line init a lt a hex gt denominator coefficients ind Ob d ite d th tents of the delay li buff d th init b lt b hex gt numerator coefficients ae Ow serve and write down e con en SO e delay line pulrer w an e input an
141. ssing Input signal is microphone input 800 Hz square wave x AO mike A square wave To better avoid overflows we use the transpose realization with sample processing algorithm for each input x do sD tap D w p D y b x sD p sO a y b x cdelay D w amp p define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 Io include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers const AO 0x4000 AO 0 5 input scale factor const D 10 D fs f1 period of square wave var dm circ w D 1 filter s delay line buffer i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line const Ds 800 wavetable s min freq fs Ds 10 Hz var dm circ s Ds square wavetable 16 As L6 s wavetable pointer and length const c 80 square wave frequency f1 c fs Ds const A 0x1000 A A0 4 square wave amplitude init s lt squartbl hex gt load wavetable const a 0x690d coefficient a 0 8207 0x690d const b 0x7486 coefficient b 0 91035 0x7486 design specs f1 800
142. stants variables and buffers ezk delay ezl delay const D 6000 max delay TD D fs 6000 8000 3 4 sec const d 2000 d th tap d 1 2 D P z 3 i er n cite w D 1 define delay line buffer Give the system an impulse by lightly tapping the table with the mike and listen to the impulse response Then speak into the mike TAAN em NG ibuffer pointer and length Bring the mike near the speaker and then give the system an impulse You zero i2 m2 L2 clear delay line should hear repeated echoes If you bring the mike too close to the speak ers the output goes unstable Draw a block diagram realization that would start processing input samples s co o s o explain the effect you are hearing Experimentally determine the distance at S p 7 which the echoes remain marginally stable that is neither die out nor di wait idle jump wait wait for interrupt and loop forever 8 interrupt service routine starts here verge Technically speaking the poles of your closed loop system lie on the input_samples ena sec_reg fenable secondary register set unit circle read input samples from codec b Change the sampling rate to 16 kHz recompile and reload keeping the value of d the same that is d 2000 Listen to the impulse response What is the axl dm rx_buf 1 left input sample d a f the delay i d gt mx1
143. to assembly language as follows mx1 dm rx_buf 2 read right input from codec tapin i2 m2 mx1 put mx1 into tap 0 of delay line m2 1 m4 1 mr 0 mxO dm i2 m2 my0 pm i4 m4 s0 hO next s1 h1 mr mr mxO myO ss mxO dm i2 m2 myO pm i4 m4 s1 h1 next s2 h2 mr mr mxO myO ss mxO dm i2 m2 myO pm i4 m4 s2 h2 next s3 h3 mr mr mxO myO ss mxO dm i2 m2 myO pm i4 m4 s3 h3 next s0 h0 mr mr mxO my0 rnd mr y if mv sat mr 3 INSTRUCTION SET TUTORIAL 14 cdelay 12 m2 update delay sr ashift mri by 2 hi scale output by factor of 2A2 4 dm tx_buf 2 srl write right output to codec The four code lines involving a MAC operation and fetching data from DM and PM memories are examples of multifunction instructions which are executable in one cycle that is 30 nsec These instructions are separated by commas instead of semicolons The first multifunction instruction clears the MAC accumulator mr to zero fetches the values of S ho into the registers mx0 myO and then post increments the buffer pointers to point to the next buffer entries that is 1 h1 All of that is done in one cycle The next code line calculates the partial product mr hoso fetches s h1 and points to 2 h2 The next line updates the partial sum mr hoso his fetches S2 h2 and points to s3 h3 The next line updates the partial sum mr hoso his h2s2
144. tput sound with that of the plain reverberator b As in the previous experiment compare the 60 dB time constants of the case D 6000 and a 0 5 and the case D 3000 and a 0 5 c Repeat part a using the transposed form implemented by the program a11 pass3 dsp Compare the output to that of allpass dsp 4 7 Lowpass Reverb The lowpass reverberator of this experiment is shown in Fig 8 2 21 of Ref 1 Setting a A1 the corresponding sample processing algorithm is x gt D gt y x yY So for each input sample x do i Sp tap D w p D e _ Vo AV Sp i Po Vo SIN i Sp uU bovo E b v l y l yo y x u z poi vi Vo b ay Ss G z p y E cdelay D w amp p The following program lowpass dsp is an implementation lowpass dsp lowpass reverb Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on lowpass c of Introduction to Signal Processing Sample processing algorithm from Eq 8 2 34 and Fig 8 2 21 for each input x do sD tap D w p D get D th tap vO a vl sD input to unit delay u bO vO b1 v1 output of feedback filter y x u filter output vl vO update unit delay p y input to D fold delay cdelay D w amp p update D fold delay 4 EXPERIMENTS 47 define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 02
145. utgers ECE Dept S J Orfanidis Jan 1996 a The constant A represents the unit amplitude of the re sampling pulse train Based on cdelay c of Introduction to Signal Processing p 177 I O equation y n x n d range of delay d 1 2 D s n Set A 0 and M 1 and recompile and run You should hear nothing Sample processing algorithm because s n becomes identically zero so that ar remains zero causing only for each input x do zeros to be sent to the codec For the next part reset A to unity y tap D w p d get d th tap p x put input x into tap 0 b With an initial choice of f 48 kHz choose successive downsampling ra i cdelay D w amp p update delay tios of M 1 2 3 4 6 8 12 16 24 48 96 corresponding to sample rates of fi 48 24 16 12 8 6 4 3 2 1 0 5 kHz In each case recompile and run the define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 4 EXPERIMENTS 24 4 EXPERIMENTS 25 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 Lab Procedure const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 a Go to the directory c adi_dsp examples delay and compile link and load Oxc85e 9 6 Oxc85f 6 615 4 this program by the following DOS commands include lt c adi_dsp macros begin dsp gt initializations and DSP macros dsp cd delay define con
146. x delay D i2 Aw L2 w delay line buffer pointer and length zero i2 m2 L2 clear delay line const Ds 4000 var dm circ sine Ds sinusoidal wavetable min frequency f1 fs Ds 8 4 2 Hz init sine lt sinetbl hex gt load one period of the wavetable generated by sinetb1 cj const c 2 signal frequency fc c f1 4 Hz 16 Asine L6 sine pointer for signal generator start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm process right channel only wavgen i6 m6 D2 c ayl ay1 D2 sin 2 pi fc t axl D2 ar axl ayl far d D2 D2 sin 2 pi fc t myl a0 mr mx1 my1 ss mr a0 x m2 ar modify i2 m2 these three lines replace the call ar ar to tap i2 m2 ar my0 because m2 ar my0 dm i2 m2 we cannot directly set m2 ar mx0 al mr mr mxO my0 rnd if mv sat mr a0 x a s1 tapin i2 m2 mx1 cdelay i2 m2 put input from mx1 into tap 0 update delay 4 EXPERIMENTS 82 write output samples to codec
147. xc854 27 42857 Oxc855 18 9 const fs 0xc850 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 f0xc85e 9 6 Oxc85f 6 615 oon nnn nnn nnn nnn nnn nnn nn nnn nnn nnn nnn include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers Const al 0x4000 const DL 3000 left feedback coefficient aL 0 50 left TD D fs 3 8 0 375 sec const aR 0x4000 Const DR 3000 right feedback coefficient aR 0 50 right TD D fs 3 8 0 375 sec var dm circ wL DL 1 var dm circ wR DR 1 left delay line buffer right delay line buffer i2 AwL L2 wL 13 AwR L3 wR left delay buffer pointer and length right delay buffer pointer and length zero i2 m2 L2 zero i3 m3 L3 clear left delay line clear right delay line start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set read input samples from codec axl dm rx_buf 1 left input sample mx1 dm rx_buf 2 right input sample sample processing algorithm for left channel mr 0 mrl axl mr x left input m
148. y m5 1 L5 0 zero i2 m2 L2 cntr L do outputs until ce ax0 dm i3 m3 tapin i2 m2 ax0 dot M 14 m4 12 m2 cdelay i2 m2 outputs dmC i5 m5 mri cntr M do transients until ce ax0 0 tapin i2 m2 ax0 dot M 14 m4 12 m2 DSP macros input signal length filter order input samples output samples delay line buffer in DM filter taps in PM read L input samples read M 1 filter taps Interupt vector table No interrupts used delay line buffer filter taps buffer input samples output samples clear delay line process L input samples read x into AX0 put x in delay line compute output in MR1 update delay output y M input off transients read x 0 into AX0 put it in delay line compute output in MR1 4 EXPERIMENTS cdelay i2 m2 transients dmci5 m5 mri idle endmod update delay output y The program firex2 dsp implements the FIR filter using the macro cfir firex2 dsp FIR example using cfir Junior DSP Lab Rutgers ECE Dept S J Orfanidis Jan 1996 Based on Example 4 2 1 of Introduction to Signal Processing The filter coefficients and are stored in the files h dec h hex The input and output signals are in the files xfir dec xfir hex yfir dec yfir hex h 0 25 1 4 x 0 25 1 4 0 50 2 4 0 25 1 4 0 25 1 4 0 50 2 4 0 25 1 4 0 25 1 4 0 50 2 4 0 50 2 4 0 25
149. yO aL tap i2 m2 DL mx0 mx0 sD D th tap mr mr mxO myO rnd mr y x a sD left output tapin i2 m2 mr1 cdelay i2 m2 put y in tap 0 update left delay 4 EXPERIMENTS 40 4 EXPERIMENTS 41 d According to this formula Teff remains invariant under the replacements dm tx_buf 1 mrl left output sample sample processing algorithm for right channel D gt 2D a gt a 0 isd 7 F at mxl mr x right input Test if this is true by running your program and hearing the output with D 6000 and a 0 5 0 25 and comparing it with the case D 3000 and my0 aR a 0 5 Repeat the comparison also with D 1500 and a 0 5 0 7071 tap i3 m3 DR mx0 mx0 sD D th tap mr mr mxO myO rnd mr y x a sD right output as l 4 6 Allpass Reverb tapin i3 m3 mr1 put y in tap 0 cdelay 13 m3 update right delay Like the plain reverberator an allpass reverberator can be used as an elementary die bak 2 smri right output sample building block for building more complicated reverberation algorithms It is given by Eq 8 2 25 of the text 1 and shown in Fig 8 2 17 Its I O equation and transfer return from interrupt function are rti at z P y n ay n D ax n x n D H z ia include lt c adi_dsp macros end dsp gt wrapup gt az f i ER Its sample process
150. zero input Sample processing code is the same as in lowpass dsp define sampling rate in kHz 0xc850 8 Oxc851 5 5125 Oxc852 16 0xc853 11 025 0xc854 27 42857 Oxc855 18 9 4 EXPERIMENTS 63 const fs Oxc85b 0xc856 32 Oxc857 22 05 Oxc859 37 8 Oxc85b 44 1 Oxc85c 48 Oxc85d 33 075 Oxc85e 9 6 Oxc85f 6 615 Io include lt c adi_dsp macros begin dsp gt initializations and DSP macros define constants variables and buffers var dm v1 state of first order feedback filter const a 0x0000 a 0 const bO Ox3fdf b0 0 499 const b1 0x3fdf b1 0 499 const D 100 f1 fs D 44100 100 441 Hz var dm circ w D 1 circular delay line delay line buffer pointer and length load w with random numbers w hex copied from w440hz hex init w lt w hex gt ax0 0 dm v1 ax0 clear feedback delay v1 0 start processing input samples wait idle jump wait wait for interrupt and loop forever interrupt service routine starts here input_samples ena sec_reg enable secondary register set mx1 0 zero input sample processing algorithm from lowpass dsp tap i2 m2 D mri mrl sD D th tap mx0 a my1 dm v1 state v1 mr mr mxO my1 rnd mr v0

Download Pdf Manuals

image

Related Search

Related Contents

Bombas centrífugas para incendios serie CX Operación  電解水素水生成器 『トリムイオンハイパー』  

Copyright © All rights reserved.
Failed to retrieve file