Continue to Site

# there is no run this code what is problem can you help please ?

Status
Not open for further replies.

#### bukhaari077

##### Newbie level 2
function ber=dscdma(Marray,N,SNR,mode,...
rate,coding,interleaver,v,gdb,delay,...

%%%Pengirim
% x=[1 0 0 1 0 0 1 1 0 1 1 0];
% N=1000;
n=log2(Marray); %--> JUmlah bit yang akan dimodulasi menjadi 1 simbol
% N=N*rate+n-mod(N*rate,n); %--> Mengubah jumlah bit yg diproses
%agar menjadi kelipatan dari jumlah bit pada 1 kali proses modulasi

for ii=1:Nuser

x(ii,=randint(1,N,[0 1]);

%Convolutional Coding --> menambahkan bit spy di penerima bisa memperbaiki
%error
if rate==1/2
trellis=poly2trellis(8,[255,162]);
elseif rate==1/3
trellis=poly2trellis(9,[557 663 711]);
elseif rate==2/3
trellis = poly2trellis([5 4],[23 35 0;0 5 13]);
end
if coding==1
outcoding=convenc(x(ii,,trellis);
elseif coding==0
outcoding=x;
end
%Blok Interleaver
if interleaver==1
baris=4;kolom=4;
blok=baris*kolom;
outint=zeros(1,size(outcoding,2));
for i=1:size(outcoding,2)/blok
outint(1,blok*i+1-blok:blok*i)=matintrlv(outcoding(1,blok*i+1-blok:blok*i),...
baris,kolom);
end
elseif interleaver==0
outint=outcoding;
end
% konversi biner ke desimal dg asumsi MSB di sebelah kiri
outdes=zeros(1,length(outint)/n);
for i=1:length(outint)/n
outdes(1,i)=bi2de(outint(1,n*i+1-n:n*i),'left-msb');
end
%Modulasi/Mapping
% outmod=pskmod(x,2);
if mode=='psk'
outmod=pskmod(outdes,Marray);
elseif mode=='qam'
outmod=qammod(outdes,Marray);
maxt=max(abs(outmod));
end

ct(ii,=repmat(h(ii,,1,size(outmod,2));
outpulse=rectpulse(outmod,Nc);

end

ind=1;
% SNR=0:2:20;
% tic
if fading==1 %SInyal kirim terkena kanal fading
if flat==1
h=raygen(size(outsum,2),v);
else
h1=raygen(size(outsum,2),v);
h2=raygen(size(outsum,2),v);
gdb=10.^(gdb/10);
p1=[zeros(1,delay(1,1)) outsum(1,1:end-delay(1,1))].*h1.*gdb(1,1);
p2=[zeros(1,delay(1,2)) outsum(1,1:end-delay(1,2))].*h2.*gdb(1,2);
h=(h1*gdb(1,1)+h2*gdb(1,2))/2;
end
elseif fading==0 %Sinyal Kirim tidak terkena kanal fading
end

for snr=SNR
%%%%Buat Noise AWGN

%Ekualisasi ZF
outek=outawgn./h;
else
outek=outawgn;
end

%%%Penerima
%Demodulasi/Demapping
if mode=='psk'
outdemod=pskdemod(outint,Marray);
elseif mode=='qam'
maxi=max(abs(outint));
outdemod=qamdemod(outint*maxi/maxt,Marray);
end

%Konversi desimal ke biner dg asumsi MSB di sebelah kiri
outbin=zeros(1,length(outdemod)*n);
for i=1:length(outdemod)
outbin(1,n*i+1-n:n*i)=de2bi(outdemod(1,i),n,'left-msb');
end
if interleaver==1
%Blok Deinterleaver
outdeint=zeros(1,size(outbin,2));
for i=1:size(outbin,2)/blok
outdeint(1,blok*i+1-blok:blok*i)=matdeintrlv(outbin(1,blok*i+1-blok:blok*i),...
baris,kolom);
end
elseif interleaver==0
outdeint=outbin;
end
%Blok viterbi decoding
if rate ==1/2
traceback=(length(outdeint)/2)-1;
elseif rate ==1/3
traceback=34;
elseif rate==2/3
traceback=34;
end
if coding==1
elseif coding==0
end

%Menghitung BER
ind=ind+1;
end
% toc
% close all
% semilogy(SNR,ber,'r-*'),xlabel('SNR (dB)'),ylabel('BER')
% grid on

%Tugas : Buat Grafik BER-SNR 3 jenis modulasi berbeda,
% BPSK, QPSK, 8PSK, Jumlah data 10000 bit, SNR:-6 s.d. 20
%Supaya mudah dan efisien, program utk menghitung BER dipisahkan
% dari program utk membuat grafik

function modulasipsk
N=100;
f=1;
x=[1 1 0 1 0 0 0 1 ];
% y=[1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 ]

y=rectpulse(x,N);
fs=N;
t=0:1/fs:1-1/fs;
% t=linspace(0,1,fs)
carrier1=sin(2*pi*f*t);
carriertot=repmat(carrier1,1,length(x));

y=2*y-1;
outmod=y.*carriertot;

close all
subplot(321),plot(x,'linewidth',3)
title('Bit Sebelum dimodulasi'),grid on
subplot(322),plot(y,'linewidth',3)
title('Bit Yang dijadikan Pulsa'),grid on
subplot(323),plot(carrier1,'linewidth',3)
title('Sinyal Carrier'),grid on
subplot(324),plot(carriertot,'linewidth',3)
title('Sinyal Carrier Total'),grid on
subplot(326),plot(outmod,'linewidth',3)
title('Sinyal Setelah dimodulasi'),grid on

function latihannomor3
n=3;
x=[0 1 ];

for i=1:n+1
x(1,i+2)=x(1,i)+x(1,i+1);
end

function latihannomor2

n=5;

% h=eye;
% p=rot90(eye)
% y=h|p
y=eye | rot90(eye)

Status
Not open for further replies.