I am trying to create 10 individual signals with on-off keying modulation format, add them up to have a final signal, and then take a Fourier transform of that signal. I tried to zero padd the final signal before taking fft so that I can correct amplitude for my spectrum based on this link: Amplitude Estimation and Zero Padding
However, I still do not get amplitude one for frequencies of interest. I am new to both Matlab and signal processing. I do appreciate any help to fix the problems. Below is my code in Matlab:
clc, clear all, close all;
NStep = 20; % the number of bits
R = 20; % Bit rate (Gbps)
Tr = 1/R; % bit period (nanosecond)
x = randi([0,1],1,NStep); % Binary information
N = length(x);
nb = 100; % Digital signal per bit
t = Tr/nb:Tr/nb:nb*N*(Tr/nb); % Time period (ns)
Digit = [];
for n = 1:1:NStep
if x(n) == 1;
sig = ones(1,nb);
else x(n) == 0;
sig = zeros(1,nb);
end
Digit = [Digit sig];
end
subplot(2,1,1)
plot(t,Digit);
xlabel('Time (ns)');
ylabel('Amplitude');
%% fft
lpad = length(Digit);
xdft = fft(Digit,lpad);
xdft = xdft(1:lpad/2+1);
xdft = xdft/length(Digit);
xdft(2:end-1) = 2*xdft(2:end-1);
fs = 1/(Tr/nb);
freq = 0:fs/lpad:fs/2;
subplot(2,1,2)
plot(freq,abs(xdft))
xlabel('Frequency (GHz)');
ylabel('Amplitude');