Different outputs from spectrogram and pwelch
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Louise Wilson
am 11 Aug. 2023
Beantwortet: Louise Wilson
am 14 Aug. 2023
When analysing an acoustic signal, I would expect to get the same results presented in a spectrogram or a PSD analysis, when using the same input variables.
However, this is not the case with my example data (xbit.mat), attached.
%Read audio file
load('xbit.mat');
Fs=96000; %sample rate
xbit=detrend(xbit);
cal=-163.287; %calibration value
% FFT inputs
window=Fs;
nfft=Fs;
overlap=Fs/2;
% Spectrogram
Calibration=10^((abs(cal))/20); % calibration value for specific device used to record data
xbit_cal=xbit*Calibration;
figure(1)
subplot(2,1,1)
[S,F,T,P] = spectrogram(xbit_cal,window,overlap,nfft,Fs,'yaxis');
surf(T,F,10*log10(P),'edgecolor','none');
colorbar;
view(0,90);
ylim([50 24000])
set(gca,'YScale','log','TickDir','out');
clim([0 120]);
ylabel('Frequency');
xlabel('Time')
ylabel(colorbar,'Intensity','VerticalAlignment','bottom','Rotation',270,'FontSize',12)
% PSD analysis
[pxx,f]=pwelch(xbit,window,overlap,nfft,fs); %perform PSD analysis
%signal, window/segment length, overlap, nfft
pxx_dB=10*log10(pxx)-cal; %convert to dB re 1µPa and calibrate
subplot(2,1,2)
semilogx(f,pxx_dB)
ylabel('Intensity')
xlabel('Frequency')
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Mrutyunjaya Hiremath
am 11 Aug. 2023
- Spectrogram Scaling: In your spectrogram analysis, you are converting the spectrogram power values to dB and applying calibration (cal) using P=((10*log10(P))-cal);. This could lead to the differences in the value ranges between the spectrogram and PSD.
- PSD Scaling: In your PSD analysis, you are calculating the PSD values using pwelch, which already provides the power spectral density values in dB. However, you are applying an additional calibration (pxx_dB=10*log10(pxx)-cal;) to the PSD values. This might be causing the PSD values to be shifted.
To maintain consistency and facilitate a direct comparison between the spectrogram and PSD, you should avoid applying additional calibrations and dB conversions to both the spectrogram and PSD values. Here's how you can modify your code:
% ... (previous code)
% Spectrogram
figure(1)
subplot(2,1,1)
[S,F,T,P] = spectrogram(xbit,window,overlap,nfft,Fs,'yaxis');
surf(T,F,P,'edgecolor','none');
colorbar;
view(0,90);
ylim([50 24000])
set(gca,'YScale','log','TickDir','out');
clim([0 120]);
ylabel('Frequency');
xlabel('Time')
ylabel(colorbar,'Intensity','VerticalAlignment','bottom','Rotation',270,'FontSize',12)
% PSD analysis
pxx=pwelch(xbit,window,overlap,nfft); %perform PSD analysis
pxx_dB=10*log10(pxx); % convert to dB re 1µPa
subplot(2,1,2)
plot(pxx_dB)
ylabel('Intensity')
xlabel('Frequency')
By removing the cal calibration and dB conversions from both the spectrogram and PSD calculations, you should get a more accurate representation of the value ranges between the two analyses. This will allow you to compare the spectrogram and PSD more directly.
Siehe auch
Kategorien
Mehr zu Spectral Estimation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!