Hi ,
Number of samples= 50000 samples.
m=[ 0 54 ...................................................]
m is the discrete signal samples .Has length of 50000
Is this code correct for the signal which has 50000 samples?
Do I use nextpow2 function?
When I used it I am getting wrong frequency components in FFT.
Here is the code i have written .
m=[ 0 54 ...................................................]; 50000 samples are there .
fs=50000000; %Sampling frequency
nfft=length(m);
%nfft=2^nextpow2(nfft);
X=fft(m,nfft); %FFT of the signal
X=X(1:nfft/2);
%take magniutde
mx=abs(X);
f=(0:(nfft/2)-1)*fs/nfft; %Frequency range
figure(1);
n=50000;
t=0:1:(n-1);
plot(t,m);
title('Multisine')
xlabel('Samples')
ylabel('Amplitude');
figure(2)
plot(f,mx);
title('FFT of signal')
xlabel('Frequency')
ylabel('Amplitude');

 採用された回答

Star Strider
Star Strider 2021 年 4 月 21 日

1 投票

Using nextpow2 is not necessary. It will make the fft calculation a bit more efficient, and it will increase the frequency resolution. See the documentation section on Computational Efficiency for an extended discussion.

6 件のコメント

632541
632541 2021 年 4 月 21 日
Thanks Star Strider..
What about the code?Because I'm using vector and 50000 samples are there?So any comments on code??
Star Strider
Star Strider 2021 年 4 月 21 日
I cannot tun the code, so I cannot determine if it is correct. You discovered — and posted a Comment to — one of my other Answers calculating discrete Fourier transforms, so I direct you to it for an example of code that analyses the signal correctly and gives the correct result.
For example, of ‘t’ is the independent variable vector, and ‘s’ is the dependent variable vector, this will compute the one-sided discrete Fourier transform, using nextpow2 to calculate the length of the fft result —
L = numel(t);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
N = 2^(nextpow2(L));
FTs = fft(s,N)/L;
Fv = linspace(0, 1, fix(numel(FTs)/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
.
632541
632541 2021 年 4 月 23 日
Thanks Star Strider
plot(Fv, abs(FTs(Iv))*2)
Why is it *2 in the code?
Star Strider
Star Strider 2021 年 4 月 23 日
The fft function produces a vector consisting of symmetrical complex-conjugate ‘positive’ and ‘negative’ frequencies (most easily seen with the fftshift function), with the original signal energy equally divided between the two. Multiplying the one-sided fft result by 2 restores the original signal amplitude.
632541
632541 2021 年 5 月 2 日
Thanks Star Strider
Star Strider
Star Strider 2021 年 5 月 2 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 4 月 21 日

コメント済み:

2021 年 5 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by