Advertisement
Guest User

Untitled

a guest
Apr 30th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Nfft = 4096;
  2. fs = 245.76e6;
  3. f1 = 13.5e6;
  4. f2 = 15.3e6;
  5.  
  6. t = 0:1/fs:(Nfft-1)/fs;
  7. vin = sin(2*pi*f1*t)/2+sin(2*pi*f2*t)/2;
  8. %9.2bit thermal noise
  9. vin = vin + randn(1, Nfft) * 1 / 2^9.2 / 2;
  10.  
  11. %Ideal 10bit quantization
  12. out = round(vin*2^10/2)+2^9;
  13.  
  14. f = linspace(0, 0.5, Nfft/2+1)*fs;
  15. OUT = fft(out, Nfft);
  16. figure(1);
  17. plot(f, 20*log10(abs(OUT(1:Nfft/2+1))));
  18.  
  19. idx = round(f1/fs*Nfft)+1;
  20. idx2 = round(f2/fs*Nfft)+1;
  21.  
  22. sig_power = abs(OUT(idx)).^2 + abs(OUT(idx2)).^2;
  23. noise_power = sum(abs(OUT(2:Nfft/2)).^2)-sig_power;
  24. SNR = 10*log10(sig_power/noise_power)+3.01;
  25. display(sprintf('SNR: %.2fdB, ENOB: %.2f bits', SNR, (SNR-1.76)/6.02));
  26.  
  27. %kill two samples
  28. out2 = out;
  29. out2(7:8:end)=0;
  30. out2(8:8:end)=0;
  31.  
  32. OUT2 = fft(out2, Nfft);
  33.  
  34. figure(2);
  35. plot(f, 20*log10(abs(OUT2(1:Nfft/2+1))));
  36.  
  37. %Find the "mixing" function
  38. mix = out2~=0;
  39. MIX = fft(mix, Nfft);
  40. MIXR = fliplr(MIX);
  41.  
  42. %Create a sparse matrix whose entries correspond to the reversed and
  43. %shifted FFT of the mixing function, as used in the periodic convolution
  44. num_impulses = sum(MIX~=0);
  45. r = filter(ones(1, num_impulses), 1, upsample(1:Nfft, num_impulses));
  46. c = zeros(Nfft, num_impulses);
  47. v = zeros(Nfft, num_impulses);
  48.  
  49. row = zeros(1,Nfft);
  50. %Go row by row to deal with the circular shift; this is slow and could
  51. %potentially be optimized
  52. for m=1:Nfft
  53. row = circshift(MIXR, m, 2);
  54. c(m, :) = find(row ~= 0);
  55. v(m, :) = row(c(m, :));
  56. end
  57. c = reshape(c', 1, Nfft*num_impulses);
  58. v = reshape(v', 1, Nfft*num_impulses);
  59.  
  60. Mk = sparse(r, c, v);
  61.  
  62. OUT_GUESS = abs(Mk)\(Nfft*abs(OUT2)');
  63.  
  64. figure(3);
  65. plot(f, 20*log10(abs(OUT_GUESS(1:Nfft/2+1))));
  66.  
  67. idx = round(f1/fs*Nfft)+1;
  68. idx2 = round(f2/fs*Nfft)+1;
  69.  
  70. display('Guessed');
  71.  
  72. sig_power = abs(OUT_GUESS(idx)).^2 + abs(OUT_GUESS(idx2)).^2;
  73. noise_power = sum(abs(OUT_GUESS(2:Nfft/2)).^2)-sig_power;
  74. SNR = 10*log10(sig_power/noise_power)+3.01;
  75. display(sprintf('SNR: %.2fdB, ENOB: %.2f bits', SNR, (SNR-1.76)/6.02));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement