length of a signal when doing fft and power spectrum analysis

조회 수: 6 (최근 30일)
C.G.
C.G. 2020년 11월 26일
댓글: dpb 2020년 11월 26일
I am undertaking experiments on a sandpile to understand self organised criticality and therefore want to plot a power spectrum of my data.
I have the following code which plots a power spectrum for me, however I was wondering if somebody could explain about the length of the signal and sampling frequency.
  1. Signal length (N): My data consists of the number of grains leaving the sandpile every second. The sandpile is supplied at a constant rate. Is the signal length just the length of time the experiment was run for?
  2. Sampling frequency (fs): It says that sampling frequency is how many samples are taken per second, does this mean that if I collect data from my experiment every second, then fs = 1?
%fft/power spectra
%set up basic parameters
signal = grains;
N = length(signal); %number of samples in the signal
fs = 1; %how many samples are taken per second
fnyquist = fs/2; %nyquist frequency
%plot a single sided power spectrum with log frequency azis
%abs is the magnitude values
%fft is a built in function that determines magnitude and phases of sinusoids present in a signal
X_mags = abs(fft(signal));
%assign frequency axis values, starting with bins from 0:N-1
bin_vals = [0 : N-1];
%to convert from bin to Hz use the standard formula: bin*fs/N, where fs and
%N are defined at the beginning
fax_Hz = bin_vals*fs/N;
%ceil rounds each element of N/2 to the nearest integer greater or equal to that element
%e.g. -1.9 is rounded to -2.0
N_2 = ceil(N/2);
%create a plot where the x axis has a log scale (semilogx)
%x axis is log Hz, ranging from 1:N2
%y axis converts the values of X_mags to dB using 20*log10
figure(2)
semilogx(fax_Hz(1:N_2), 20*log10(X_mags(1:N_2)))
xlabel('Frequency (Hz)')
ylabel('Power (dB)');
title({'Single-sided Power spectrum' ...
' (Frequency in shown on a log scale)'});
axis tight
  댓글 수: 1
dpb
dpb 2020년 11월 26일
This doesn't seem like a use for spectral analyses...but the signal length is simply the number of observations (samples) in the data set, yes, and the sampling frequency is what the number of samples/unit time was. This only matters to determine the actual frequency in the resultant frequency range.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by