0
$\begingroup$

This question already has an answer here:

I am analyzing sounds of daily activities recorded by a smartphone. For example walking, getting up from bed, falling, running etc.. (one at the time). Let’s take one them. My goal is to

  • convert from time domain to frequency domain

  • divide it in bins of 10 Hz wide

  • calculate the average FT magnitude in each of these bins.

My questions are:

  • Which FFT Magnitude spectrum should I use between the following graphs?
  • How should proceed to divide my signal (99144 total samples with 44100 sample rate) in 10 Hz bins? Can I achieve this just by using Matlab's pwelch function?

-> Here the frequencies of the single-sided magnitude are 0 – 22000 Hz -> Which means I should have 2200 bins of 10 Hz -> Should I just create a new array and put the average mean of all values between 0 – 10 Hz, 10 – 20 Hz and so on?

enter image description here

[signal,fs]=audioread(filename); % fs = 44100
N = length(signal); % N = 94144

%% Single-sided magnitude spectrum with frequency axis in Hertz
% Each bin frequency is separated by fs/N Hertz.
X_mags = abs(fft(signal));
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N; % conversion Hz - Bins
N_2 = ceil(N/2);
figure;
subplot(4,1,1);
plot(fax_Hz(1:N_2), X_mags(1:N_2))
xlabel('Frequency (Hz)')
ylabel('Magnitude');
title('Single-sided Magnitude spectrum (Hertz)');
axis tight

%% Single-sided magnitiude spectrum in decibels and Hertz
X_mags = abs(fft(signal));
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N;
N_2 = ceil(N/2);
subplot(4,1,2);
plot(fax_Hz(1:N_2), 10*log10(X_mags(1:N_2)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)');
title('Single-sided Magnitude spectrum (Hertz)');
axis tight

%% Single-Sided Amplitude Spectrum
NFFT = 2^nextpow2(N); 
Y_NFFT = fft(signal,NFFT)/N;
f_NFFT = fs/2*linspace(0,1,NFFT/2+1);
subplot(4,1,3);
plot(f_NFFT,2*abs(Y_NFFT(1:NFFT/2+1))) 
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

%% Pwelch defaut values
subplot(4,1,4);
pwelch(signal,[],[],[],fs);
title(sprintf('Pwelch defaut values'));
$\endgroup$

marked as duplicate by MBaz, lennon310, jojek May 16 '17 at 10:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0
$\begingroup$

Here the answer for those facing similar problems:

if your Fs = 44100 Hz (in my case) and you want fft resolution of 10 Hz then use fft resolution N = 44100/10 = 4410.

You can then take just 4410 samples of signal or split the stream into segments (+ overlap) each = 4410 samples and directly average the bins (fft output).

FFT covers frequencies from -Fs/2 to +Fs/2 so you don't need to worry about single sided spectrum.

You better average the amplitude values from each bin directly(not the dB), then you can convert the mean to power in dB:

fft_mean = mean(ffts1,ffts2,ffts3,...);

plot(20*log10(f,abs(fft_mean))); %in dB
$\endgroup$

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