Running into error when using pwelch for FFT

조회 수: 34 (최근 30일)
Benjamin Colbert
Benjamin Colbert 2022년 5월 7일
댓글: Jonas 2022년 5월 8일
I am trying to conduct a FFT on a wav file in order to then calculate SPL within a bandwidth (120-450hz). I am using code from another answered question and I get hung up on an error:
Error using signal.internal.spectral.welchparse>segment_info
The length of the segments cannot be greater than the length of the input signal.
Error in signal.internal.spectral.welchparse (line 34)
[L,noverlap,win] = segment_info(M,win1,noverlap1);
Error in welch (line 55)
signal.internal.spectral.welchparse(x,esttype,args{:});
Error in pwelch (line 170)
[welchOut{1:nargout}] = welch(x,funcName,inputArgs{:});
Error in snip_extractor (line 16)
[sensor_spectrum, freq] = pwelch(samples,w,NOVERLAP,NFFT,Fs);
My code follows. I am loading a 30sec wav file and then selecting a 5sec period with the file for analysis. Any help here would be most appreciated:
[y,Fs]=audioread('67649542.060120201700.wav') %Load fullfile
snips = y([163840:327680], [1]) %Extract data from period of interest
%%%Borrowed code from https://www.mathworks.com/matlabcentral/answers/636155-plotting-fft-for-audio-wav-file
NFFT = (Fs/2);
NOVERLAP = round(0.75*NFFT);
w = hanning(NFFT);
samples = length(snips)
dt = 1/Fs
t = (0:dt:(samples-1)*dt)
[sensor_spectrum, freq] = pwelch(samples,w,NOVERLAP,NFFT,Fs);
sensor_spectrum_dB = 20*log10(sensor_spectrum);
figure(1),semilogx(freq,sensor_spectrum_dB);grid
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(freq(2)-freq(1)) ' Hz ']);
xlabel('Frequency (Hz)');ylabel(my_ylabel);
  댓글 수: 3
Benjamin Colbert
Benjamin Colbert 2022년 5월 7일
Would it? I'm very new at coding this. I have previously used prebuilt tools (e.g., PAMGuide) but I have a need now to write something specific for my code. Eventually I will run this to extract RMS dB re 1uPa between 120hz and 450hz for 30sec samples of about 300 wav files. I need to do some type of FFT in order to extract the sequency component of the signal.
Jonas
Jonas 2022년 5월 8일
is there a reason for re 1*10^-6 Pa and not 20*10^-6 Pa?
do you want to calculate one SPL value for one file in your frequency range or do you want to extract multiple SPL values over time for each file?

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

답변 (1개)

Jonas
Jonas 2022년 5월 7일
편집: Jonas 2022년 5월 7일
[
sensor_spectrum, freq] = pwelch(samples,w,NOVERLAP,NFFT,Fs);
should be
[sensor_spectrum, freq] = pwelch(snips,w,NOVERLAP,NFFT,Fs);
since samples is only a scalar and not your data vector
the displayed error says, that your window of length fs/2 is lager than the given data vector, which is 1x1 by mistake

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by