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

Untitled

a guest Mar 25th, 2019 67 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));%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. xtest = ((f/2)/nsamples:(f/2)/nsamples:(f/2));%frequency values for the signal
22. plot(xtest, fftshift(psd));
23. xlabel("Frequency")
24. ylabel("Weight")
25.
26. grid on;
27. for counter=1:length(nbit)
28.     M = 2^nbit(counter);
29.     SNR = M^2./(1+4*(M^2-1)*pe);
30.     figure(3)
31.     semilogx(pe,10*log10(SNR))
32.     grid on;
33.     hold on
34.     dv = 2*v/M;
35.     partition = -v+dv:dv:v-dv;
36.     codebook = -v+dv/2:dv:v-dv/2;
37.     [index,quanz] = quantiz(sig,partition,codebook);
38.     words = de2bi(index,nbit(counter));
39.     for c2=1:length(pe)
40.         out = bsc(words,pe(c2));
41.     end
42. 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