• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 21st, 2019 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. clear;
2. close all;
3.
4. a = 20;
5. M = 10000;
6. X = zeros(M, 1);
7. for i = 1:M
8.     X(i) = ((a/3)^2)*randn();
9. end
10.
11. U = zeros(M, 7);
12. delta = [0, 0, 0, 0, 0, 0, 0];
13.
14. for R = 1:7
15.     quants = 2^R;
16.     delta(R) = 2*a/quants;
17.     for i = 1:M
18.         U(i, R) = delta(R)*fix(X(i)/delta(R));
19.         if X(i) >= 0
20.             U(i, R) = U(i, R) + delta(R)/2;
21.         else
22.             U(i, R) = U(i, R) - delta(R)/2;
23.         end
24.     end
25. end
26.
27. SNR = zeros (7, 1);
28. A = X.^2;
29. for R = 1:7
30.     B = (X-U).^2;
31.     SNR(R) = 10*log10(sum(A)/sum(B(:,R)));
32. end
33.
34. t = -20:0.0001:20;
35. f = (1/(a/3*sqrt(2*pi)))*exp(-(t.^2)/(2*((a/3)^2)));
36. plot(t, f);
37. tmp = zeros (M, 1);
38. epsilon = zeros (7,1);
39. TheorSNR = zeros (7, 1);
40. for R = 1:7
41.     for i = 1:M
42.         func = @(T) ((X(i)-U(i))^2)*((1/(a/3*sqrt(2*pi)))*exp(-(T.^2)/(2*((a/3)^2))));
43.         if X(i) >= 0
44.             tmp(i) = integral(func, delta(R)*fix(X(i)/delta(R)), delta(R)*fix(X(i)/delta(R))+delta(R));
45.         else
46.             tmp(i) = integral(func, delta(R)*fix(X(i)/delta(R)) - delta(R), delta(R)*fix(X(i)/delta(R)));
47.         end
48.     end
49.     epsilon(R) = sum(tmp);
50.     TheorSNR(R) = 10*log10(((a/3)^2)/epsilon(R));
51. end
52.
53. t = 1:1:7;
54. figure(2);
55. plot(t, SNR, t, TheorSNR);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top