length of a signal when doing fft and power spectrum analysis
2 次查看(过去 30 天)
显示 更早的评论
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.
- 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?
- 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
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 Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!