1
$\begingroup$

I have some experimental data from a shaker (vibration exciter) running at sine $10\textrm{ Hz}$ for test purposes (recorded using an ADXL345 accelerometer with $f_s=512\textrm{ Hz}$. I would like to upsample these data for varies ratios, e.g. a factor of $\times 10$. How do I update the FFT in MATLAB accordingly? As of now, upsampling appears to shift results in the $x$-direction as shown in the figure below (black is the original signal, blue is the resampled signal with cutoff at $1/2\times f_s$):

enter image description here

Peak at approximately 80 Hz (black) appears at approximately 40 Hz (blue).

But I would like to increase the resolution within the existing data without shifting results in the $x$-direction?

MWE:

close all; clear all; clc

fs=512; % sampling frequency

load data.mat

t=X{1}; % time
y=X{4}; % accelelation

y=y./1024; % calibration of data

%% resampling

%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
ups=10; % upsampling rate
%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%

dns=1; % downsampling rate
fu = fs*ups; % upsampling frequency
% tu = t(1):1/fu:t(end)-1/fu;
ytu=resample(y,ups,dns);

%% FFT and plot

figure; 

x=y;
[N,m] = size(x);

freq = 0:fs/length(x):fs/2; %frequency array for FFT
xdft = fft(x); %Compute FFT
xdft = 1/length(x).*xdft; %Normalize
xdft(2:end-1) = 2*xdft(2:end-1);
semilogy(freq,abs(xdft(1:floor(N/2)+1)),'k-')
hold on

x=ytu;
[N,m] = size(x);

freq = 0:fu/length(x):fu/2; %frequency array for FFT
xdft = fft(x); %Compute FFT
xdft = 1/length(x).*xdft; %Normalize
xdft(2:end-1) = 2*xdft(2:end-1);
semilogy(freq,abs(xdft(1:floor(N/2)+1)),'b.')

xlabel('Frequency (Hz)');
ylabel('Accel (g)');
grid on;

Here is the link to data.mat.

$\endgroup$
  • $\begingroup$ resample applies a lowpass filter to your data. Why not interpolate between accel samples? $\endgroup$ – Atul Ingle Jul 8 '17 at 16:40
2
$\begingroup$

Your whole problem is due to the fact that you have made a wrong assumption.

Increasing the sample rate does not increase the frequency resolution. It will increase the Nyquist frequency (the highest frequency you can represents) while keeping the same resolution. And that is exactly the phenomenon you have encountered with Matlab.

In other word, after upsampling by a factor of 10, your spectrum goes up to $2560 \text{ Hz}$, not $256\text{ Hz}$. I think you figured that out as the script you provided takes that in consideration while the figure you have posted does not.

In order to improve the resolution, you have to take a longer acquisition in time.

Your frequency resolution is evaluated as : $$R = \frac{F_s}{N}$$ Where :

  • $R$ is the resolution
  • $N$ your number of FFT samples
  • $F_s$ your sampling frequency

In the script you have provided, you did increase the sampling frequency by a factor of $10$, but you also increased the number of samples by the same factor. Thus, you kept the exact same resolution of $512/90000 = 0.568 \text{Hz}$.

In order to get a better (smaller) resolution you have to:

  1. Increase $N$ without changing $F_s$. In other word longer acquisition
  2. Decrease $F_s$ without changing $N$. In other word longer acquisition

Hope that helps!

$\endgroup$

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.