FFT of ON OFF signal

2 次查看(过去 30 天)
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

采纳的回答

David Goodmanson
David Goodmanson 2019-9-22
编辑:David Goodmanson 2019-9-22
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))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by