Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENCM515 Standard and Custom FIR filters

Similar presentations


Presentation on theme: "ENCM515 Standard and Custom FIR filters"— Presentation transcript:

1 ENCM515 Standard and Custom FIR filters
* 07/16/96 This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during your presentation In Slide Show, click on the right mouse button Select “Meeting Minder” Select the “Action Items” tab Type in action items as they come up Click OK to dismiss this box This will automatically create an Action Item slide at the end of your presentation with your points entered. ENCM515 Standard and Custom FIR filters M. R. Smith, Electrical and Computer Engineering University of Calgary, Canada ucalgary.ca *

2 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Compare performance of optimized “C” code -- coded the “best way” (software circular buffer using “if” statements or using pointer “mask operations” -- your choice” hand coded non-parallel code hand coded parallel code for FIR filter operations Compare your optimized code with what is available in DSP library files in VisualDSP directories Need to show filter works -- OFFLINE Test audio performance Write a suitable report discussing results. 10/7/2019 ENCM High speed FIR filters Copyright

3 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Delay is not only thing to take into account Four paths from 2 sources in front 10/7/2019 ENCM High speed FIR filters Copyright

4 Transfer function h30(f)
10/7/2019 ENCM High speed FIR filters Copyright

5 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
FIR schematic diagram Find the Hcoeffs from Bessinger thesis -- convert to floats 10/7/2019 ENCM High speed FIR filters Copyright

6 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Result we need to get LEFT_EAR = LEFT_SOUND * FIR H_ RIGHT_SOUND * FIR H330 RIGHT_EAR = LEFT_SOUND * FIR H_ RIGHT_SOUND * FIR H30 Take it a step at a time Get 1 H30 FIR filter to work -- Cut and paste to get timing for 4 FIR -- cache implications here Test using MONO | IMPULSE Output identical to FIR coefficients Audio-wise -- Try H_30 on both ears next Finally use H_ never been satisfied with gain 10/7/2019 ENCM High speed FIR filters Copyright

7 Coding Characteristics
4 FIR filters associated with 2 sound sources Bessinger Thesis describes 32 coefficients for each filter Actually only 2 sets of filter coefficients need to be stored because of system symmetry. Warning -- convert delay lines to store “float values” Warning -- convert coefficients to float values not integer. Need to store current and 31 previous sound values as a minimum. Will need both left and right delay lines 10/7/2019 ENCM High speed FIR filters Copyright

8 General Concept for Real Time FIR code
For ever { ReadSource(&left_ear, &right_ear); arrayleft[N-1] = leftear arrayright[N-1] = rightear leftear = rightear = 0; // Two FIR filter h(0, 30) -- will need 2 more for (count = 0, count < FIRlength - 1, count++) { leftear = leftear + arrayleft[count] * fir(count); // convert to pointer ops!! rightear = rightear + arrayright[count]* fir[count]; } // Handle delay component of FIR via Memory Move for (count = 1, count < FIRlength - 1, count++) { arrayleft(count - 1) = arrayleft(count); arrayright(count - 1) = arrayright(count); } WriteSource(leftear, rightear); // 10/7/2019 ENCM High speed FIR filters Copyright

9 FIR code -- impliment in “C”
DM float arrayleft[N], arrayright[N], PM float FIR[N] void ProcessSound( int leftear, int rightear, int *newleft, int *newright) { float left, right; arrayleft[N-1] = (float) leftear WHY FLOAT? arrayright(N-1) = (float) rightear left = right = 0; // Two FIR filter h(0, 30) -- need 2 more for (count = 0, count < FIRlength - 1, count++) { left = left + arrayleft[count] * fir(count); // Use pointer ops right = right + arrayright[count]* fir[count]; } // Handle delay component of FIR for (count = 1, count < FIRlength - 1, count++) { arrayleft(count - 1) = arrayleft(count); arrayright(count - 1) = arrayright(count); } *newleft = (int) left; *newright = (int) right; // 10/7/2019 ENCM High speed FIR filters Copyright

10 Practical findings -- FIR
My FIR filters directly in assembly code but no optimizing (meaning no pipelining, no folding of coefficients to take into account symmetry, nothing fancy at all). Obvious distortions in audio signal (missing samples) when implemented 4 FIRs (hardware loops each with 4 cycles). Suggestions -- get 1 FIR filter to work using “OFFLINE” and “IMPULSE”. Why? 10/7/2019 ENCM High speed FIR filters Copyright

11 FIR filter -- practical concepts
When testing the filter operations DON'T USE the true filter to start with. Instead test the filter responses as follows float h30[32] = { }; float h330[32] = { }; Then test (OFFLINE) with h30[ ] loop, then h330[ ] loop, then both. This should give a signal with zero delay??????? When using real h30 or h might be useful to have some method to control overall filter gain -- see next slide for my approach When implementing filters watch out for “1-outness” in memory position/accesses 10/7/2019 ENCM High speed FIR filters Copyright

12 Testing -- FIR filter gain and deafness
Filter gain is not unity -- not sure you want it unity. Add the following code to main() to control gain in real time without recompiling (or else you’ll go deaf -- what you say?) float h30gain = 1.0; ditto for h330[] float h[30] = { etc. } main( ) { for (count = 0; count < 32, count++) h30[count] = h30[count] * h30gain; Change value of h30gain with debugger before running the code. Make sure you re-download the code before running again -- Why? 10/7/2019 ENCM High speed FIR filters Copyright

13 Special Properties -- FIR filters in “C”
float array[ARRAYLENGTH] oldest input stored first -- position 0 newest input stored last -- position ARRAYLENGTH - 1 THIS MEANS float fircoeff[FIRLENGTH] coefficient a0 stored last -- position FIRLENGTH - 1 pm float *firpt = &fircoeff[FIRLENGTH - 1]; float *arraypt = &array[ARRAYLENGTH - 1]; float result = 0; for (count = 0; count < FIRLENGTH; count++) { result = result + (*firpt) * (*arraypt); firpt--; arraypt--; } result = result / gain; 10/7/2019 ENCM High speed FIR filters Copyright

14 Look ahead to future concerns
* 07/16/96 When we use use “hardware circular” buffers then the line float *arraypt = &array[ARRAYLENGTH - 1]; SHOULD not be present as arraypt will be stored in some sort of non-volatile global index register and accessing a circular buffer This means that we ensure that arraypt is returned to its previous value after using it. 10/7/2019 ENCM High speed FIR filters Copyright *

15 Generic FIR filters in “C”
float *arraypt = &array[ARRAYLENGTH - 1]; -- Done ONCE during setup Inside the FIR routine -- FIR COEFFICIENTS ARE NOT IN A CIRC BUFFER float *firpt = &fircoeff[FIRLENGTH - 1]; MAY NOT STAY TRUE float result = 0; SEE NEXT SLIDE for (count = 0; count < FIRLENGTH; count++) { result = result + (*firpt) * (*arraypt); firpt--; arraypt--; } // Need to restore arraypt to original position arraypt = arraypt + FIRLENGTH (or is it FIRLENGTH + 1) // Can be handled by Modify(arraypt, FIRLENGTH) // and many other approaches result = result / gain; 10/7/2019 ENCM High speed FIR filters Copyright

16 Multiple FIR filters -- very easy
PM float *firpt = &fircoeff_H30[FIRLENGTH - 1]; float result = 0; for (count = 0; count < FIRLENGTH; count++) { result = result + (*firpt) * (*arraypt); firpt--; arraypt--; } result30 = result arraypt = arraypt + FIRLENGTH -- reset to start of array firpt = &fircoeff_H330[FIRLENGTH - 1]; for (count = 0; count < FIRLENGTH; count++) { /* Identical code */ finalresult = result + result // Repeat for other ear arraypt = arraypt + FIRLENGTH etc 10/7/2019 ENCM High speed FIR filters Copyright

17 Speed -- L and R Generic FIR filters
float result, result2 = 0; for (count = 0; count < FIRLENGTH; count++) { value = *firpt; result = result + value * (*arraypt_left); result2 = result2 + value * (*arraypt_right); firpt--; arraypt_left--; arraypt_right--; } Speed improvement -- less access of FIR coefficients CAN ALSO get more speed with folding FIR coefficients if symmetric -- h30 but not h330 for (count = 0; count < FIRLENGTH / 2; count++) { value = *firpt; result = result + value * ( (*arraypt) *(arraypt - LENGTH + count)) ; 10/7/2019 ENCM High speed FIR filters Copyright

18 FIR filters in assembly code -- not circular buffer
.extern array .extern fircoeff <-- put into pm memory? #define firpt IPM_register? #define arraypt IDM_register? #define result float_register? #define temp1, temp2, temp float_register????? // float *firpt = &fircoeff[FIRLENGTH - 1]; firpt = fircoeff + FIRLENGTH - 1; <- NOT AN ADDITION -- CONSTANTS ONLY // float *arraypt = &array[ARRAYLENGTH - 1]; arraypt = array + ARRAYLENGTH - 1; <- NOT AN ADDITION result = 0.0; // float result = 0; for (count = 0; count < FIRLENGTH; count++) { // *firpt, *arraypt, firpt--, arraypt--; temp1 = dm(firpt, -1), temp2 = pm(arraypt, -1) temp3 = temp1 * temp2; // (*firpt) * (*arraypt) result = result + temp3 } 10/7/2019 ENCM High speed FIR filters Copyright

19 FIR filters -- Software circular buffer -- Pseudocode
// float *firpt = &fircoeff[FIRLENGTH - 1]; firpt = fircoeff + FIRLENGTH - 1; // float *arraypt = &array[ARRAYLENGTH - 1]; NOTE: array <= arraypt <= array + ARRAYLENGTH - 1; result = 0.0; // float result = 0; for (count = 0; count < FIRLENGTH; count++) { // *firpt, *arraypt, firpt--, arraypt--; temp1 = dm(firpt, -1), temp2 = pm(arraypt, -1) temp3 = temp1 * temp2; // (*firpt) * (*arraypt) result = result + temp3; R1 = arraypt // Handle circular buffer operations R2 = array compare (R1, R2) // Can’t compare I registers? if GE jump(PC, OKAY); // NOT delayed branch R2 = array + ARRAYLENGTH arraypt = R2 OKAY: } // endfor // Remember to adjust back arraypt before exitting 10/7/2019 ENCM High speed FIR filters Copyright

20 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
10/7/2019 ENCM High speed FIR filters Copyright

21 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Register allocations Interrupt routines already using Alternate B0, I0, L0, B1, I1, L1 Suggest you control left storage and right storage of sounds using B2 for left and B3 for right -- hence the question from Lab. 2 about using only 1 pointer Query -- do we ALSO need to add the sound delays from Lab.2 on top of the FIR delay? Read thesis and check. WATCH OUT -- my code uses I8,L8,B8 10/7/2019 ENCM High speed FIR filters Copyright

22 FIR filters -- Some rough assembly language concepts
// float *firpt = &fircoeff[FIRLENGTH - 1]; firpt = fircoeff + FIRLENGTH - 1; <- NOT AN ADDITION -- use MODIFY // float *arraypt = &array[ARRAYLENGTH - 1]; NOTE: array <= arraypt <= array + ARRAYLENGTH - 1; result = 0.0; // float result = 0; #define saveOldI3 R??? saveOldI3 = arraypt // <-- KEY OPERATION for (count = 0; count < FIRLENGTH; count++) { // *firpt, *arraypt, combined with firpt--, arraypt--; temp1 = dm(firpt, -1), temp2 = pm(arraypt, -1) // <-- POST-MOD temp3 = temp1 * temp2; // (*firpt) * (*arraypt) result = result + temp3; // Circular buffer operations automatic } arraypt = saveOldI // <-- KEY OPERATION // ?? Where is new sound value added -- 10/7/2019 ENCM High speed FIR filters Copyright

23 Important things to note
Circular buffers only work on Post-modify instructions can’t use R2 = dm(count, I2) If interrupt routines are too slow then will lose output signals 21k interrupts currently block each other automatically Timer interrupt is low priority compared to Serial Port interrupt -- See table Page 3-25 Both interrupts are using the circular buffers -- Race condition occurring 10/7/2019 ENCM High speed FIR filters Copyright

24 Current Loop -- 3 * FIRLENGTH cycles
EH?? -1 and DM/PM access Above is PSEUDOCODE Allowed but slow or not allowed? NOTE: -- Will give correct theoretical timing, but what things are wrong with the code? 10/7/2019 ENCM High speed FIR filters Copyright

25 Also see CCI articles by Smith
Example to use for Systematic Approach to optimizing DSP algorithm for FIR filter Also see CCI articles by Smith

26 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Step 1 -- unroll loop 10/7/2019 ENCM High speed FIR filters Copyright

27 Step 2 -- Identify independence
10/7/2019 ENCM High speed FIR filters Copyright

28 Step 3 -- refill ALU/Memory pipeline
10/7/2019 ENCM High speed FIR filters Copyright

29 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Step 4 -- refold loop 10/7/2019 ENCM High speed FIR filters Copyright

30 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Comparison of loops Time * FIRLENGTH Time 5 + FIRLENGTH - 2 10/7/2019 ENCM High speed FIR filters Copyright

31 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Key issue or not Current loop shows both dm[ ] and pm[ ] access occurring with a constant post-modify value (-1) I claim that this is legal but causes a processor stall so that takes extra cycles No need to use preset modify registers minus1dm and minus1pm unless really worried about speed -- True or False? 10/7/2019 ENCM High speed FIR filters Copyright

32 ENCM515 -- High speed FIR filters Copyright smithmr@ucalgary.ca
Lab. 4 Compare performance of optimized “C” code -- coded the “best way” (software circular buffer using “if” statements or using pointer “mask operations” -- your choice” hand coded non-parallel code hand coded parallel code for FIR filter operations Compare to what is used in library files Need to show filter works -- OFFLINE Test audio performance Write a suitable report discussing results. 10/7/2019 ENCM High speed FIR filters Copyright


Download ppt "ENCM515 Standard and Custom FIR filters"

Similar presentations


Ads by Google