FFT of ON OFF signal
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
imran khan
am 20 Sep. 2019
Bearbeitet: David Goodmanson
am 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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239049/timedomain.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239050/FFT.jpeg)
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
0 Kommentare
Akzeptierte Antwort
David Goodmanson
am 22 Sep. 2019
Bearbeitet: David Goodmanson
am 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))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!