Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 2.41 KB | None | 0 0
  1. using Plots;
  2. using FFTW;
  3. using DSP;
  4.  
  5. # read I/Q samples
  6. function gimme()
  7.     data = reinterpret(Complex{Float32}, read("/home/domagoj/gqrx_20181207_153804_437485000_1800000_fc.raw"));
  8.     dataLength = floor(Int, size(data,1));
  9.  
  10.     # multiply by complex exponential -> frequency shift; desired carrier frequency is shifted to origin
  11.     T = 1/1800000;
  12.     shiftFreq = 23000;
  13.     shiftExp = [exp(-im*2*pi*shiftFreq*n*T) for n in 1:dataLength];
  14.     data = data.*shiftExp;
  15.  
  16.     # create Butterworth lowpass filter
  17.     responsetype = Lowpass(1500; fs=1800000);
  18.     prototype = Butterworth(40);
  19.  
  20.     # apply created filter to sample array
  21.     db = filt(digitalfilter(responsetype, prototype), data);
  22. end
  23. try
  24.     db;
  25. catch
  26.     db = gimme();
  27. end
  28. #=
  29. # generate and plot 32768-FFT results
  30. windowSize = 32768;
  31. n = floor(Int, size(dbdAvg,1)/windowSize);
  32. for i in 1:n
  33.     F = fft(dbdAvg[(i-1)*windowSize+1:i*windowSize]);
  34.     F = fftshift(F);
  35.     Fr = [20*log10(abs(i)) for i in F];
  36.     plot(Fr[15000:17500])
  37.     #ylims!(-30, 60);
  38.     gui();
  39.     sleep(0.04)
  40. end
  41. =#
  42. function unweraper(x)
  43.     state = 0;
  44.     retArr = Array{Float32}(length(x));
  45.  
  46.     for i=1:length(x)
  47.         w = x[i];
  48.         if (pi - w < 0.01)
  49.             state--;
  50.         end
  51.         if (w + pi < -0.0)
  52.             state++;
  53.         end
  54.         ret[i] = x[i] + pi*state;
  55.     end
  56.     retArr
  57. end
  58.  
  59. angularv = (x, i) -> i> 1 && i <= length(x) ? angle(x[i]/x[i-1]) : 0
  60. dbAng = angle.(db) |> unwrap;
  61. #dbd = [diffNaiv(dbAng, i) for i=1:length(dbAng)];
  62. #dbav = [angularv(dbAng, i) for i=1:length(dbAng)];
  63. #dbdAvg = [Statistics.median((dbd[i-30:i])) for i=31:30:length(dbd)];
  64. diffNaiv = (x, i) -> i> 1 && i <= length(x) ? x[i] - x[i-1] : typeof(x[1])(0);
  65. Q = imag.(data) - real.(data) .|> sign ;
  66. Qd = [diffNaiv(dbAng, i) for i=2:length(dbAng)];
  67. dbd = sign.(dbd);
  68. # plot d_phi / dt
  69. windowSize = 1024;
  70. n = floor(Int, size(Q,1)/windowSize);
  71. b = true;
  72. function a(arrr, amp, frame, ws)
  73.     for i in (18 * ws):(20 * ws)
  74.         currr = arrr[(i-1)*windowSize+1:i*windowSize];
  75. #       if (currr |> findmin)[1] >  | true
  76.             plot(currr)
  77.             if (amp > 0)
  78.                 ylims!(-amp,amp)
  79.             end
  80.             #xlims!(-.01,.01)
  81.             gui()
  82.             sleep(frame)
  83.             if !b
  84.                 break;
  85.             end
  86.             println(i);
  87. #       end
  88.     endcd
  89.     println("Stopped");
  90. end
  91. @async a(Qd, 0.01, 0.04, windowSize)
  92. #=
  93. # plot "live" constellation diagram
  94. windowSize = 10240;
  95. n = floor(Int, size(db,1)/windowSize);
  96. for i in 1:n
  97.     plot(db[(i-1)*windowSize+1:i*windowSize])
  98.     ylims!(-.01u,.01)
  99.     xlims!(-.01,.01)
  100.     gui();
  101.     sleep(0.04)
  102. end
  103. =#
  104.  
  105. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement