# How Can I correct amplitude and smoothness of FFT?

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
xdft = xdft/length(Digit);
xdft(2:end-1) = 2*xdft(2:end-1);
fs = 1/(Tr/nb);
subplot(2,1,2)
plot(freq,abs(xdft))
xlabel('Frequency (GHz)');
ylabel('Amplitude');

• Hi Amy- A quick hint for now and hoping to have more time later to give you complete details: There is no need to actually model the carrier (when you multiply by cos(2*piFct)) This makes the simulation take so much longer and doesn't really give any information. I suggest modelling the On-Off keying at baseband and then what shows up as bin 0 in the FFT will be exactly what you would see at any particular carrier. As a quick test consider what the FFT of a square wave looks like and then compare that to a OOK sequence with 10101010 pattern. Commented Jan 12, 2022 at 0:15
• Hi Dan, Many thanks for your reply. I found out that the magnitude f my spectrum depends on how many ones I have in the binary stream. Am I right? The reason why I multiply by cos(2*piFct) is that I want to create a signal for a WDM channel.
– Amy
Commented Jan 14, 2022 at 17:49
• You don’t need to multiply by the carrier to see what the spectrum will look like at the carrier: if you omit that then your spectrum will be centered at bin 0 and you can just relabel that bin as the carrier (it will look the same!). I am not sure what you are referring to with your question about the number of ones Commented Jan 14, 2022 at 19:22
• Oh! I got what you mean now, thanks. Concerning amplitude, I meant based on how many ones and zeros I have in a stream of bit, the amplitude in the peaks of my spectrum can be unity or not. Am I right?
– Amy
Commented Jan 14, 2022 at 19:35
• Show me two simple examples in your posted question with plots and from that please clarify there what your question is Commented Jan 14, 2022 at 19:36

The expected spectrum for one stream of on-off keying modulation would be the given by the Fourier Transform of the base pulse (a rectangular pulse in this case) assuming random data and sufficient number of samples. In the example used by the OP there are an insufficient number of samples to provide the statistical distribution representing "random data". Additionally note that FFT scales by the total number of samples $$N$$, so to normalize we would divide the result by $$N$$. For on/off keying, we expect to have on average half the number of samples as "1" and the other half as "0", so without normalization the magnitude of the FFT should be $$N$$ and go down as a Sinc function given the Fourier Transform of a rectangular pulse is a Sinc. I show this with the example code below:

N = 1000;
data = sign(rand(N,1)*2-1);
oversamp = 10;
modulated = data * ones(1, 10);
modout = reshape(modulated',1, N*10);
fout =  fft(modout, 2**18)./N;
freqaxis = [-2^17+1: 2^17]/2^18;
figure
plot(freqaxis, fftshift(20*log10(abs(fout))))


Note: the spectrum plotted is that with 10 samples per symbol, and the result is a "Dirichlet Kernel" rather than a true Sinc function. The Dirichlet Kernel approaches a Sinc as the number of samples per symbol goes to infinity.