• API
• FAQ
• Tools
• Archive
daily pastebin goal
59%
SHARE
TWEET

# Untitled

a guest Mar 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. clear all;
2. close all;
3. clc;
4.
5. v = 1;%signal amplitude (max "voltage")
6. f = 1.6e4;%sampling frequency (arbitrary)
7. nbit = [4 6 8];%signal bit depth(s)
8.
9. nsamples = 1e4;
10. pe = logspace(-9,-1,500);%Probabilities of Error (of binary symmetrical channel)
11. sig = 2*v*(rand(1, nsamples)) -v ;%signal (randomly generated)
12. figure(1);
13. grid on;
14. hold on;
15. histogram(sig,20,'normalization','pdf');%ProbabilityDensityFunction histograms
16. xlabel("Amplitude")
17. ylabel("PDF")
18.
19. psd = abs(fft(sig)).^2;%Square PowerSpectralDensity vector
20. figure(2);
21. df = f/nsamples;
22. xtest = (-f/2:df:f/2-df);%frequency values for the signal
23. plot(xtest, fftshift(psd));
24. xlabel("Frequency")
25. ylabel("Weight")
26.
27. grid on;
28. for counter=1:length(nbit)
29.     M = 2^nbit(counter);
30.     SNR = M^2./(1+4*(M^2-1)*pe);
31.     figure(3)
32.     semilogx(pe,10*log10(SNR))
33.     grid on;
34.     hold on
35.     dv = 2*v/M;
36.     partition = -v+dv:dv:v-dv;
37.     codebook = -v+dv/2:dv:v-dv/2;
38.     [index,quanz] = quantiz(sig,partition,codebook);
39.     words = de2bi(index,nbit(counter));
40.     for c2=1:length(pe)
41.         out = bsc(words,pe(c2));
42.     end
43. end
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