Running into error when using pwelch for FFT
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);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); 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); fft MATLAB Answers — New Questions