Advertisement
martaczaska

ZPS_3_5_1

May 31st, 2020
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #include <dsplib.h>
  2. #include <testsignal.h>
  3. #include <okno_hamminga.h>
  4. #include <stdio.h>
  5.  
  6. #define NUM_SAMPLES 2048
  7. #define Nr 1000
  8.  
  9.  
  10. int klarnet[NUM_SAMPLES];
  11. int testowa[NUM_SAMPLES]; //potem usunąć
  12. int okno_h[NUM_SAMPLES];
  13. int bufor[NUM_SAMPLES];
  14. int autokorelacja[Nr];
  15.  
  16. int i;
  17. int j = 0;
  18. int roznica = 0;
  19. int znalezione;
  20. int maks = 0;
  21.  
  22. const long f_s = 48000;
  23. const int N = 2048;
  24.  
  25. void maksimum(int* tablica, int podloga, int number){
  26.     znalezione = 0;
  27.  
  28.     for(i = 0; i < number; i++){
  29.             if(tablica[i] > podloga){
  30.                 roznica = tablica[i] - tablica[i - 1];
  31.                 if(roznica > 0){
  32.                     maks = i;
  33.                     znalezione = 1;
  34.                     printf("Indeks maksimum: ");
  35.                     printf("%d \n", maks);
  36.                 }
  37.                 else{
  38.                     if(znalezione==1 && (roznica < 0)){
  39.                         //znalezione = 0;    //myslałam, że potrzebne dla 5. ale co nie
  40.                         break;
  41.                     }
  42.                     else{continue;}
  43.                 }
  44.             }
  45.             else{continue;}
  46.     }
  47.  
  48. }
  49.  
  50. void czestotliwosc(int p){
  51.     long df = f_s / N;
  52.     df = df << 15;
  53.     long f_maks = _smpy(p, df); // >> 15;              //format Q30
  54.  
  55.     //f_maks = _sround(f_maks) >> 15;
  56.  
  57.     printf("Częstotliwosc znalezionego maksimum wynosi: ");
  58.     printf("%d \n", f_maks);
  59.  
  60. }
  61.  
  62.  
  63. void main(void) {
  64.     int x = okno_hamminga[0];
  65.  
  66.  
  67.     for (i = 0; i < NUM_SAMPLES; i++){
  68.         klarnet[i] = testsignal[i];
  69.         //klarnet[i] = _smpy(okno_hamminga[i], testsignal[i]);
  70.         testowa[i] = testsignal[i];
  71.     }
  72.  
  73.     rfft((DATA*)klarnet, NUM_SAMPLES, SCALE);                  // do 2.
  74.  
  75.     for (i = 0; i < NUM_SAMPLES; i++){
  76.         klarnet[i] = _smpy(klarnet[i], klarnet[i]);          //do 2.
  77.     }
  78.  
  79.     for(i = 2; i < NUM_SAMPLES; i = i + 2){
  80.         klarnet[j] = klarnet[i] + klarnet[i + 1];
  81.         j++;
  82.     }
  83.  
  84.     sqrt_16((DATA*)klarnet, (DATA*)klarnet, 512);
  85.  
  86.     maksimum(klarnet, 2800, NUM_SAMPLES);
  87.     printf("%d \n", maks);
  88.     czestotliwosc(maks);
  89.  
  90.     /////////////////do 5. :
  91.  
  92.     for (i = 0; i < NUM_SAMPLES; i++){
  93.             bufor[i] = testsignal[i] >> 4;
  94.         }
  95.  
  96.     acorr((DATA*)bufor, (DATA*)autokorelacja, NUM_SAMPLES, Nr, bias);
  97.  
  98.     maksimum(autokorelacja, 10, NUM_SAMPLES);
  99.     //koniec 5.
  100.  
  101.     while (1); // do not exit
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement