2
$\begingroup$

I have 6 column vectors $(\mathbf A_x,\mathbf A_y, \mathbf A_z, \mathbf G_x, \mathbf G_y, \mathbf G_z)$ taken by accelerometer to analyze the vibration of a construction. Each column is a $64998\times 1$ valued-vector and overall time is $664$ seconds. I've done something but I don't know how I can fix it.

Fs=97.885;
L=64998;
NFFT=2^nextpow2(64998);

AXdft = fft(Ax);
AXdft=AXdft(1:NFFT/2+1,:);

freq = linspace(0,Fs,NFFT/2+1);

plot(freq,2*abs(AXdft));
xlabel('Hz');ylabel('Magnitude');

figure;
plot(freq,20*log10(abs(AXdft)));
xlabel('Hz');ylabel('dB');
title('Plot in dB');

BTW I will add each column over other via hold on

getting a figure but missing its size. The frequency doesn't appear in figure and I guess I must do PSD, Can anyone help?

$\endgroup$
1
$\begingroup$

I believe that your problem is using nextpow2 to set the fft length. fft(x) returns a vector length(x). fft(x) is not constrained to a power of 2. If you want to set a particular size by zero padding, use fft(x,N). NFFT=length(Ax) is the actual size of DFT.

Using psd has advantages but if you use the proper size, your code will work (assuming I am correct) . Taking a single long DFT isn't an accepted way to estimate a psd, unless you are looking for very fine, high snr features.

$\endgroup$
  • $\begingroup$ Thanks for your care, i've tried and used only L instead of using NFFT. The code creates a figure where data doesn't appear. I think, it doesn't encompass because of axis(x or y) that can't be fixed with 'axis' command. Scaling it 1/64998 sounds well but doesn't work. What I miss here. ( By the way Ax is a column vector and has 64998x1 value) $\endgroup$ – huytergan Aug 4 '17 at 22:10
  • $\begingroup$ Matlab takes a very long time to render 65,000 points. Your display doesn't nearly have the pixels to render the data. Break up your data in 2048 point segments Don't use hold on until you get something to work. Think about the constraints of your display $\endgroup$ – Stanley Pawlukiewicz Aug 4 '17 at 22:19
  • $\begingroup$ just tried that you said.I don't think that's the reason it doesn't show anything. $\endgroup$ – huytergan Aug 4 '17 at 22:45
  • $\begingroup$ MATLAB doesn't render NaN values. Look at your numbers. $\endgroup$ – Stanley Pawlukiewicz Aug 4 '17 at 23:01
  • $\begingroup$ thx there was some NaN data and i fixed them, but MATLAB has still been returning NaN values when I try to access 'abs(AXdft)', the whole numbers which taken by accelerometer in excel, are real numbers. $\endgroup$ – huytergan Aug 5 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.