Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- close all;
- clc;
- v = 1;%signal amplitude (max "voltage")
- f = 1.6e4;%sampling frequency (arbitrary)
- nbit = [4 6 8];%signal bit depth(s)
- nsamples = 1e4;
- pe = logspace(-9,-1,500);%Probabilities of Error (of binary symmetrical channel)
- sig = 2*v*(rand(1, nsamples)) -v ;%signal (randomly generated)
- figure(1);
- grid on;
- hold on;
- histogram(sig,20,'normalization','pdf');%ProbabilityDensityFunction histograms
- xlabel("Amplitude")
- ylabel("PDF")
- psd = abs(fft(sig)).^2;%Square PowerSpectralDensity vector
- figure(2);
- df = f/nsamples;
- xtest = (-f/2:df:f/2-df);%frequency values for the signal
- plot(xtest, fftshift(psd));
- xlabel("Frequency")
- ylabel("Weight")
- grid on;
- for counter=1:length(nbit)
- M = 2^nbit(counter);
- SNR = M^2./(1+4*(M^2-1)*pe);
- figure(3)
- semilogx(pe,10*log10(SNR))
- grid on;
- hold on
- dv = 2*v/M;
- partition = -v+dv:dv:v-dv;
- codebook = -v+dv/2:dv:v-dv/2;
- [index,quanz] = quantiz(sig,partition,codebook);
- words = de2bi(index,nbit(counter));
- for c2=1:length(pe)
- out = bsc(words,pe(c2));
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement