FFT of single max sided from signal

2 ビュー (過去 30 日間)
Ramesh Bala
Ramesh Bala 2021 年 3 月 17 日
コメント済み: Mathieu NOE 2021 年 3 月 17 日
I'm trying to get frequency of signal.But after applying FFT it doesn't shows 200e3 (which is given) ?
Attaching the code and picture how the end result should be.
Thanks
load ('T1.mat')
f = 200e3; % frequency
T = 1/f ;
sf = 1/t(1,2);
n =5;
tt = n*T;
t1 = 0:1/sf:tt; % total time cycle
sinewave = sin(2*pi*f*t);
figure(1)
plot(t,sinewave)
%fourier
figure
xdft = fft(sinewave,1024);
plot(abs(xdft))

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 3 月 17 日
hello
this is the code fixed :
FYI, the frequency in your code is 200 and not 100 kHz as in image , but you can easily change that
cheers
clc
clearvars
load ('T1.mat')
f = 200e3; % frequency
T = 1/f ;
sf = 1/t(1,2);
n =5;
tt = n*T;
t1 = 0:1/sf:tt; % total time cycle
sinewave = sin(2*pi*f*t);
figure(1)
plot(t,sinewave)
%fourier
nfft = 1024;
xdft = fft(sinewave,nfft);
% one sidded fft spectrum % Select first half
if rem(nfft,2) % nfft odd
select = (1:(nfft+1)/2)';
else
select = (1:nfft/2+1)';
end
xdft = xdft(select)*2/nfft;
freq_vector = (select - 1)*sf/nfft;
figure
plot(freq_vector/1000,abs(xdft)) % freq divided by 1000 to be displayed in kHz
xlabel('kHz');
ylabel('Amplitude');
xlim([0 2*f/1000]);
  2 件のコメント
Ramesh Bala
Ramesh Bala 2021 年 3 月 17 日
Thank you Mathieu
Mathieu NOE
Mathieu NOE 2021 年 3 月 17 日
you're welcome !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by