martaczaska

trojkatny

May 2nd, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 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.  
  10. void saw(int* tablica, unsigned int dl_tablicy, unsigned int step){
  11.     int amplituda = 0;
  12.     int i;
  13.     tablica[0] = 0;
  14.     for(i = 1; i < dl_tablicy; i++){
  15.         amplituda = amplituda + step;
  16.         tablica[i] = amplituda;
  17.     }
  18. }
  19.  
  20. void rect(int* tablica_prost, unsigned int dl_tablicy, unsigned int step, int prog){
  21.         int amplituda = 0;
  22.         int i;
  23.         for(i = 1; i < dl_tablicy; i++){
  24.             if(amplituda < prog){
  25.                 tablica_prost[i] = 32767;
  26.             }
  27.             else{
  28.                 tablica_prost[i] = -32768;
  29.             }
  30.             amplituda = amplituda + step;
  31.         }
  32. }
  33.  
  34. void tri(int* tablica_tri, unsigned int dl_tablicy, unsigned int step){
  35.     signed int amplituda = 0;
  36.     signed int bezwzgledna = 0;
  37.         int i;
  38.         tablica_tri[0] = 0;
  39.         for(i = 1; i < dl_tablicy; i++){
  40.             amplituda = amplituda + step;
  41.  
  42.             bezwzgledna = amplituda < 0 ? -amplituda : amplituda;
  43.             tablica_tri[i] = ((bezwzgledna<<1) - 32767);
  44.         }
  45.  
  46. }
  47.  
  48. void main(void) {
  49.     //saw(pila, NUM_SAMPLES, krok);
  50.     //rect(prostokatny, NUM_SAMPLES, krok, 0);
  51.     tri(trojkatny, NUM_SAMPLES, krok);
  52.  
  53.     while (1); // do not exit
  54. }
Advertisement
Add Comment
Please, Sign In to add comment