Advertisement
DeaD_EyE

fftfreqcenter (Python/JS)

Feb 15th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. def fftfreqcenter2(samples, speed_step, doppler_min_speed):
  2.     speeds = [doppler_min_speed]
  3.     for _ in range(samples):
  4.         speeds.append(speeds[-1] + speed_step)
  5.     return speeds
  6.  
  7.  
  8.  
  9. function fftfreqcenter(samples, speed_step, doppler_min_speed) {
  10.     var result = [doppler_min_speed];
  11.     for (var i=1; i < samples; i++) {
  12.         result[i] = result[i-1] + speed_step
  13.         }
  14.     return result;
  15.     }
  16.  
  17.  
  18.  
  19. You receive every 20th frame a state over websocket with following content:
  20. "state": {"mode": "CW", "sample_rate": 122880, "window_size": 512, "bandwidth": 180000000, "fft": true, "window_function": "hanning", "vco_signal": null, "doppler": {"min_speed": null, "max_speed": null}, "motor": {"start": 0, "stop": 360, "run": false}}}
  21.  
  22. Now I see it, min_speed and max_speed should never be null. After fixing my bug they have always a valid value.
  23.  
  24. To calculate the speed for the distance axis (X on A, Y on B), you need to know the number of samples, speed_step (in m/s) and doppler_min_speed as offset.
  25.  
  26.  
  27. fftfreqcenter(14, 3.0, 0);
  28.  
  29. # Array(14) [ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, … ]
  30. This means the first sample is for 0 m/s, second sample 3.0 m/s ...
  31. After starting the server, it's set automatically to it's maximum range (from negative to 0 to positive).
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. ######################OLD########################################
  55.  
  56. # I have copied parts from:
  57. # https://github.com/numpy/numpy/blob/v1.15.0/numpy/fft/helper.py#L124-L169
  58. #
  59. # The task was, to have a fftfreqcenter function in JavaScript, which
  60. # uses instead of a sampling space, a provided value, which can be anything
  61. # In our case: Distance (FMCW) or Speed (CW)
  62.  
  63. def fftfreqcenter(samples, multiplicator):
  64.     NP = (samples-1) // 2 + 1
  65.     NN = -samples // 2
  66.     pos = list(range(0, NP))
  67.     neg = list(range(NN, 0))
  68.     result = neg + pos
  69.     return [r * multiplicator for r in result]
  70.  
  71.  
  72. function fftfreqcenter(samples, multiplicator) {
  73.     var NP = Math.floor((samples - 1) / 2 + 1);
  74.     var NN = Math.floor(-(samples / 2));
  75.     var pos = [];
  76.     var neg = [];
  77.     var idx = 0;
  78.     for (var i=0; i < NP; i++) {
  79.         pos[idx] = i * multiplicator;
  80.         idx++;
  81.         }
  82.     idx = 0;
  83.     for (var i=NN; i < 0; i++) {
  84.         neg[idx] = i * multiplicator;
  85.         idx++;
  86.         }
  87.     return neg.concat(pos);
  88.     }
  89.  
  90. // fftfreqcenter(16, 1)                                                        
  91. // [-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  92.  
  93. fftfreqcenter(16, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement