clear; bits = 64; threshold = 0.5; %Generate 64 random values. Check help on rand() function. data = rand(1, bits); %Quantize the random values only between two levels; 0 and 1. for i=1:length(data) if data (i) > threshold data2(i) = 1; else data2(i) = 0; end end %Commands for plotting the data. subplot(4, 1, 1); stairs(data2) title('Original Digital Data'); ylabel('Amplitute'); axis([0 bits -0.2 1.2]); grid off; %%%%%%%%%%%%%%%Enconding using NRZ-L%%%%%%%%%%%%%%%%%%%%%%% %nrzl_enc is a function defined in another file nrzl_enc.m data3 = nrzl_enc(data2); %Commands for plotting the data. subplot(4, 1, 2); stairs(data3) title('NRZ-L Encoded Digital Data'); ylabel('Amplitute'); axis([0 bits -1.2 1.2]); grid off; %%%%%%%%%%%%%%%Enconding using NRZ-L%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%Expand Your Sammple Space%%%%%%%%%%%%%%%%%%% sampleRate = 16; Y1 = reshape(ones(sampleRate, 1)*data3, 1, sampleRate*bits); %%%%%%%%%%%%%%%Expand Your Sammple Space%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%FFT%%%%%%%%%%%%%%%%%%% N=sampleRate*bits; FFT_Y1 = abs(fft(Y1, N)); FFT_Y1 = fftshift(FFT_Y1); F = [-N/2:N/2-1]/N;; subplot(4, 1, 3); plot(F, FFT_Y1); xlabel('frequency / f s') %%%%%%%%%%%%%%%FFT%%%%%%%%%%%%%%%%%%%