Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.93 KB | None | 0 0
  1. // “Alone” - Edgar Allan Poe
  2. chdir('home/')
  3. exec('ADC.sce')
  4.  
  5. fs = 10000
  6. quant_levels = linspace(-1, 1, 200) // we need more quantity levels
  7. recorded_data = ADC(13, quant_levels, fs)
  8. recorded_samples = size(recorded_data)(1)
  9.  
  10.  
  11. sin_ampl = 0.1
  12.  
  13. // get best value for sin_freq in possible range (120, 210)
  14. sin_freqs=zeros(1,91)
  15.  
  16. for i = 120:210
  17.     step_size = i*(2*%pi)/fs
  18.     samples = [1:recorded_samples]*step_size
  19.     sin_sig = sin_ampl*sin(samples)
  20.     sin_freqs(1, i - 120 + 1) = sum(sin_sig' .* recorded_data)  
  21. end
  22.  
  23. sin_freq = 120 + find(sin_freqs==max(sin_freqs)) - 1
  24.  
  25. step_size = sin_freq*(2*%pi)/fs;
  26. samples = [1:recorded_samples]*step_size;
  27. sin_sig = sin_ampl*sin(samples)
  28.  
  29. f = figure(1)
  30. clf
  31. plot(recorded_data - sin_sig' + 0.1, '--o') // +0.1 adjusts amplitudes to 0
  32. gca.data_bounds = [0, -1; fs, 1]
  33. xlabel('Sample')
  34. ylabel('Amplitude')
  35. playsnd(recorded_data, fs)
  36. savewave('record', recorded_data, fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement