martaczaska

white_noise

May 2nd, 2020
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. #include <dsplib.h>
  2.  
  3. #define NUM_SAMPLES 5000
  4. #define krok 137
  5.  
  6. int pila[NUM_SAMPLES];
  7. int prostokatny[NUM_SAMPLES];
  8. int trojkatny[NUM_SAMPLES];
  9. int sinus[NUM_SAMPLES];
  10. int dsplib_sin[NUM_SAMPLES];
  11. int white_noise[NUM_SAMPLES];
  12.  
  13. void saw(int* tablica, unsigned int dl_tablicy, unsigned int step){
  14.     int amplituda = 0;
  15.     int i;
  16.     tablica[0] = 0;
  17.     for(i = 1; i < dl_tablicy; i++){
  18.         amplituda = amplituda + step;
  19.         tablica[i] = amplituda;
  20.     }
  21. }
  22.  
  23. void rect(int* tablica_prost, unsigned int dl_tablicy, unsigned int step, int prog){
  24.         int amplituda = 0;
  25.         int i;
  26.         for(i = 1; i < dl_tablicy; i++){
  27.             if(amplituda < prog){
  28.                 tablica_prost[i] = 32767;
  29.             }
  30.             else{
  31.                 tablica_prost[i] = -32768;
  32.             }
  33.             amplituda = amplituda + step;
  34.         }
  35. }
  36.  
  37. void tri(int* tablica_tri, unsigned int dl_tablicy, unsigned int step){
  38.     signed int amplituda = 0;
  39.     signed int bezwzgledna = 0;
  40.         int i;
  41.         tablica_tri[0] = 0;
  42.         for(i = 1; i < dl_tablicy; i++){
  43.             amplituda = amplituda + step;
  44.  
  45.             bezwzgledna = amplituda < 0 ? -amplituda : amplituda;
  46.             tablica_tri[i] = ((bezwzgledna<<1) - 32767);
  47.         }
  48. }
  49.  
  50. /*void sint(int* tablica_sin, unsigned int dl_tablicy, unsigned int step){
  51.         int amplituda = 0;
  52.         int i;
  53.         long a_1 = pi;
  54.         long a_2 = pow(pi, 3)/3;
  55.         long a_3 = pow(pi, 5)/5;
  56.         long a_4 = pow(pi, 7)/7;
  57.         tablica_sin[0] = 0;
  58.         for(i = 1; i < dl_tablicy; i++){
  59.             amplituda = amplituda + step;
  60.             tablica_sin[i] = a_1*amplituda - a_2*pow(amplituda, 3) + a_3*pow(amplituda, 5) - a_4*pow(amplituda, 7);
  61.         }
  62. }*/
  63.  
  64.  
  65. void main(void) {
  66.     //saw(pila, NUM_SAMPLES, krok);
  67.     //rect(prostokatny, NUM_SAMPLES, krok, 0);
  68.     //tri(trojkatny, NUM_SAMPLES, krok);
  69.     //sint(sinus, NUM_SAMPLES, krok);
  70.     //ushort oflag = sine (DATA *pila, DATA *dsplib_sin, 5000);
  71.     //sine((DATA*)pila, (DATA*)dsplib_sin, NUM_SAMPLES);
  72.     rand16init();
  73.     rand16((DATA*)white_noise, NUM_SAMPLES);
  74.  
  75.     while (1); // do not exit
  76. }
Advertisement
Add Comment
Please, Sign In to add comment