FFT of ON OFF signal

2 views (last 30 days)
imran khan
imran khan on 20 Sep 2019
Edited: David Goodmanson on 22 Sep 2019
clc,close all,clear all
codn=70;
% fc=6e+3;
fs=36000;
bode=1000;
code=round(rand(1,codn));
code_len=round(1/bode/(1/fs));
for i=1:codn
x((i-1)*code_len+1:code_len*i)=code(i);
end
figure(1)
plot(x)
axis([0 2520 -0.5 1.5])
timedomain.jpg
y=abs(fft(x))
figure(2)
title('orignal baseband signal')
xlabel('time');
ylabel('amplitude')
df=-fs/2:fs/length(y):fs/2-1; (PROBLEM IN THIS FREQUENCY RANGE )
plot(df,y)
FFT.jpg
This is my code which i have write to take FFT of ON OFF signal but issue is that i am unable to find exact frequency spectru(df=-fs/2 : fs/length(y) : fs/2-1) of ON OFF signal

Accepted Answer

David Goodmanson
David Goodmanson on 22 Sep 2019
Edited: David Goodmanson on 22 Sep 2019
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))

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!