How to scale the frequency axis after performing fft?

조회 수: 55 (최근 30일)
Hasan Alkhater
Hasan Alkhater 2016년 9월 14일
댓글: ASAD RASHEED 2019년 1월 16일
Hello, I am trying to analyse signals aquired via an accelerometer for a person walking. suppose I choose the sampling frequency to be 100 Hz. then I would scale the frequency vector as follows
% code
N = length(Xabs);
fgrid = fs*(0:(N-1))/(N);
After I plot, the x-axis of the plot is scaled based on the sampling frequency being 100 Hz. Say the location of the dominant frequency in the plot is 4Hz. Now, if I change the sampling frequency to 1000, the location of the dominant frequency is ten times the previous location.
I have a feeling that my explanation is kinda messy. Here is the question: How can I scale the frequency axis such that, no matter what the sampling frequency is, the location of the dominant frequency is correct and does not change?
here is the complete script I use for your reference
fs = 100;
X = fft(x); % Obtain the DFT using the FFT algorithm
Xabs = abs(X); % Obtain the magnitude
N = length(Xabs);
fgrid = fs*(0:(N-1))/(N);
Xabs = Xabs(1:floor(N/4));
fgrid = fgrid(1:floor(N/4));
plot(fgrid,Xabs);
  댓글 수: 1
ASAD RASHEED
ASAD RASHEED 2019년 1월 16일
Why are you taking the faxis and magnitude till N/4? Should it be till N/2?

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

채택된 답변

dpb
dpb 2016년 9월 15일
Plot versus frequency instead of samples...the dominant frequency won't necessarily be in the same place but it'll show up at the correct frequency (and the same input signal sampled at differing rates will be the same location, of course)...
L=length(y); % series length
Fs=100; % or whatever is actual sampling frequency
f = Fs/2*linspace(0,1,NFFT/2+1); % single-sided positive frequency
X = fft(y)/L; % normalized fft
PSD=2*abs(X(1:L/2+1))) % one-sided amplitude spectrum
If you apply the accelerometer sensitivity to your input signal, you should get actual acceleration with due respect for no windowing, etc., ...
  댓글 수: 8
Hasan Alkhater
Hasan Alkhater 2016년 9월 20일
Got it I was thinking that this is because it is an estimate, which is why there is this slight difference
but it turns out to be due to the actual number of increments not being used
thank you ^^
dpb
dpb 2016년 9월 22일
Yeah, I was too lazy to type the extra parens around the (N-1) term initially and the approximation was good-enough to prove the point of where the error lay...

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by