Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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

Status
Not open for further replies.

bukhaari077

Newbie level 2
Joined
Jun 21, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
function ber=dscdma(Marray,N,SNR,mode,...
rate,coding,interleaver,v,gdb,delay,...
flat,fading,Nc,ua,Nuser)

%%%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

%Spreading
h=hadamard(Nc);
ct(ii,:)=repmat(h(ii,:),1,size(outmod,2));
outpulse=rectpulse(outmod,Nc);
outspread(ii,:)=ct(ii,:).*outpulse;

end

outsum=sum(outspread,1);

ind=1;
% SNR=0:2:20;
% tic
%Fading Rayleigh
if fading==1 %SInyal kirim terkena kanal fading
if flat==1
%Flat fading
h=raygen(size(outsum,2),v);
outfading=h.*outsum;
else
%Freq. Selective Fading
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);
outfading=p1+p2;
h=(h1*gdb(1,1)+h2*gdb(1,2))/2;
end
elseif fading==0 %Sinyal Kirim tidak terkena kanal fading
outfading=outsum;
end



for snr=SNR
%%%%Buat Noise AWGN
outawgn=awgn(outfading,snr+10*log10(log2(Marray)/Nc),'measured');

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

%Despreading dan integrator
outdespread=ct(ua,:).*outek;
outint=intdump(outdespread,Nc);

%%%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
datadekoding=vitdec(outdeint,trellis,traceback, 'trunc', 'hard');
elseif coding==0
datadekoding=outdeint;
end

%Menghitung BER
[p,ber(1,ind)]=symerr(x(ua,:),datadekoding);
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(n);
% p=rot90(eye(n))
% y=h|p
y=eye(n) | rot90(eye(n))
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top