Error in FFT calculation

조회 수: 10 (최근 30일)
KALEESH
KALEESH 2023년 10월 3일
댓글: Star Strider 2023년 10월 3일
Why the FFT value shows higher value in the cut signal when compared to whole signal, it should be opposite right?
close all
clear all
clc
load("allSignals.mat");
Fs = 50e6; % Sampling frequency
T = 1/Fs; % Sampling period
L = 7500; % change as required
t = (0:L-1)*T; % Time vector
X = allSignals(1,:);
plot(t,X)
title("Signal ")
xlabel("t ")
ylabel("X(t)")
% fft
Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
figure ; % after cut
X1 = allSignals(1,500:1100);
L1 = length(X1);
Y1 = fft(X1);
P21 = abs(Y1/L1);
P11 = P21(1:L1/2+1);
P11(2:end-1) = 2*P11(2:end-1);
f1 = Fs*(0:(L1/2))/L1;
plot(f1,P11)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")

채택된 답변

Star Strider
Star Strider 2023년 10월 3일
The value for ‘L’ is 7500 and for ‘L1’ is 601.
If you change:
P21 = abs(Y1/L1);
to
P21 = abs(Y1/L);
you will get the expected result (magnitude of about 40 rather than about 500).
load("allSignals.mat");
Fs = 50e6; % Sampling frequency
T = 1/Fs; % Sampling period
L = 7500; % change as required
t = (0:L-1)*T; % Time vector
X = allSignals(1,:);
plot(t,X)
title("Signal ")
xlabel("t ")
ylabel("X(t)")
% fft
Y = fft(X);
L = length(X) % <— ADDED
L = 7500
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
figure ; % after cut
X1 = allSignals(1,500:1100);
L1 = length(X1);
Y1 = fft(X1);
% P21 = abs(Y1/L1);
P21 = abs(Y1/L); % <— CHANGED
P11 = P21(1:L1/2+1);
Warning: Integer operands are required for colon operator when used as index.
P11(2:end-1) = 2*P11(2:end-1);
f1 = Fs*(0:(L1/2))/L1;
plot(f1,P11)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
.
  댓글 수: 2
KALEESH
KALEESH 2023년 10월 3일
Indeed it worked ,one question how about zero padding in this case ? is it right to use in this case or when it should be used?
L = 2*length(x1);
Y1 = fft(X1,L); % instead of Y1 = fft(X1);
Star Strider
Star Strider 2023년 10월 3일
Zero-padding is appropriate.
It would be better to use this:
L = length(X1);
NFFT = 2^nextpow2(L);
Y1 = fft(X1,NFFT);
or better yet, this:
Y1 = fft(X1(:).*hann(L),NFFT);
since the window function corrects for the fft being finite, providing a more accurate result, and a power-of-2 fft length significantly improves its efficiency. Zero-padding it also improves the frequency resolution.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by