time domain and frequency domain

11 views (last 30 days)
imran khan
imran khan on 31 Oct 2019
Commented: imran khan on 31 Oct 2019
Dear fellows,i am facing problem in my code below.Problem is that signal in time domain does not give me correct value of N,i mean value of N should be like 2^N.Please anyone can solve this issue,and also bit confuse to calculate by data rate,frequency and time(tvec) is in second or milisecond or microsecond.I am not so much good in these things thanks in advance.Please do not change value of tvec(0-0.1).
OR
If anyone has code wich is similar to my results in time domain and frequency domain then please share it to me.
clc,close all,clear all
codn=100;
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
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(1,:)+0.5)
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
pic1.jpg
y = fftshift(fft(x2)/N);
z=abs(y);
figure(2)
plot(fvec,abs(y))
title('FFT')
xlabel('frequency')
ylabel('amplitude')
pic2.jpg

Answers (1)

Daniel M
Daniel M on 31 Oct 2019
Code looks fine to me. Not sure what you mean by N being 2^N. The only thing I would tweak is setting
tvec = (0:N-1)*delt;
As for your units of fvec and tvec, they are all based off of fs. If that is in Hz then fvec is in Hz and tvec is in seconds.
  5 Comments
Daniel M
Daniel M on 31 Oct 2019
I'm talking about the several other questions you have posted. Myself and others have given you plenty of advice that you have not implemented, or have given feedback on. In this particular question you don't even specify what you want. I get the feeling that you don't know what you want. If you did, you would be able to explain it properly.

Sign in to comment.

Categories

Find more on Electrical Block Libraries 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!