martaczaska

arni

May 17th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. #include <dsplib.h>
  2.  
  3. #define NUM_SAMPLES 5000                                                               
  4. #define N 57                                                                           
  5. #define krok 137                                                                       
  6.  
  7. const short filtr_fir[] = {-30, -32, -36, -41, -46, -51, -53, -50, -41,                
  8. -23, 6, 49, 106, 178, 267,372, 492, 624, 766, 914, 1064, 1212, 1353,
  9. 1482, 1594, 1687, 1755, 1797, 1811, 1797, 1755, 1687, 1594, 1482, 1353,
  10. 1212, 1064, 914, 766, 624, 492, 372, 267, 178, 106,49, 6, -23, -41
  11. , -50, -53, -51, -46, -41, -36, -32, -30};  
  12.                                        
  13. short white_noise[NUM_SAMPLES];
  14. short pila[NUM_SAMPLES];
  15. short wynik[NUM_SAMPLES];
  16.  
  17. short bufor[N + 2];
  18. short probka = 0;
  19. short obliczona = 0;
  20. int k;
  21.  
  22.  
  23. void saw(short* tablica, unsigned int dl_tablicy, unsigned int step){              
  24.     int amplituda = 0;
  25.     int i;
  26.     tablica[0] = 0;
  27.     for(i = 1; i < dl_tablicy; i++){                                                   
  28.         amplituda = amplituda + step;
  29.         tablica[i] = amplituda;
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. void blockfir(short* input, const short* filter, short* output, int numSamples, int numFilter){
  36.     int j;
  37.     int i;
  38.  
  39.     for(j = 0; j < numSamples; j++){                                               
  40.         long y = 0;
  41.  
  42.         for(i = 0; i < N; i++){                                                        
  43.             if(i > j || i == j){break;}                                                
  44.             y = _smaci(y, input[j-i], filter[i]);                                      
  45.         }
  46.  
  47.         output[j] = (short)(_sround(y) >> 15);                                         
  48.     }
  49. }
  50.  
  51.  
  52.  
  53. void main(void) {
  54.     rand16init();                                                                      
  55.     rand16((DATA*)white_noise, NUM_SAMPLES);  
  56.                                            
  57.     saw(pila, NUM_SAMPLES, krok);                                                      
  58.  
  59.     //blockfir(white_noise, filtr_fir, wynik, NUM_SAMPLES, N);                         
  60.     //blockfir(pila, filtr_fir, wynik, NUM_SAMPLES, N);                                
  61.  
  62.     //fir((DATA*)white_noise, (DATA*)filtr_fir, (DATA*)wynik, bufor, NUM_SAMPLES, N);  
  63.     //fir((DATA*)pila, (DATA*)filtr_fir, (DATA*)wynik, bufor, NUM_SAMPLES, N);          
  64.  
  65.  
  66.     for(k = 0; k < NUM_SAMPLES; k++){                                                
  67.         //probka = white_noise[k];
  68.         probka = pila[k];
  69.         fir((DATA*)&probka, (DATA*)filtr_fir, (DATA*)&obliczona, bufor, 1, N);           
  70.         wynik[k] = obliczona;
  71.     }
  72.  
  73.     while (1); // do not exit
  74. }
Add Comment
Please, Sign In to add comment