Hi imran,
you appear to be pretty close on this. The code below uses ftshift to put f = 0 at the middle of the freq array, and uses a freq array with the same span as yours but shifted appropriately.
Another modoification concerns dc offset in the time domain. The pulse train has an average value of approximately 1/2 (not exactly 1/2 due to the random nature of the pulses) which leads to a large uninteresting spike at f = 0 that dominates the freq domain data. Subtracting 1/2 off of the data before the fft gives a reasonable peak at f = 0.
Also the fft is divided by the number of points N to give the corrrect amplitude in the freq domain.
codn=70;
% fc=6e+3;
fs=36000;
bode=1000;
code=round(rand(1,codn));
code_len=round(1/bode/(1/fs))
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii);
end
x2 = x-(1/2); % get rid of most of the dc peak
% set up time and frequency arrays
fs = 36000;
N = length(x);
delt = 1/fs;
delf = fs/N;
tvec = (1:N)*delt;
fvec = (-N/2:N/2-1)*delf; % shifted frequency array
figure(1)
plot(tvec,x2)
ylim([-1 1.5])
y = fftshift(fft(x2)/N);
figure(2)
plot(fvec,abs(y))