Hi @지호,
Thanks for your questions about the `pspectrum` function and how it processes your pressure data in Pascals. I’ve gone through your comments and prepared a detailed explanation that should clarify the calculations and physical meaning of the outputs.
1. Physical meaning of `p` from pspectrum
You asked: “I want to ask what a power spectrum value's physical meaning is. How is it related to my input, 'Pascal'?”
When your input is in Pascals (Pa), `pspectrum` computes the *power spectrum*, which is in Pa^2 — that is, the squared pressure amplitude. Physically, it represents how much acoustic energy (pressure power) is present at each frequency and, for spectrograms, at each point in time.
2. What calculations are applied to the input
You also asked: “I wonder what calculations are applied on my input values (Pa). Do you know the exact formula?”
The process is:
1. Segmentation: The signal is divided into overlapping segments.
2. Windowing: Each segment is multiplied by a Kaiser window to reduce spectral leakage. The shape of this window is controlled by the `Leakage` parameter.
3. FFT: The Fourier transform of each windowed segment is calculated.
4. Power calculation: The magnitude of the FFT is squared, normalized by the window energy, and scaled for one-sided spectra.
* If your input is x(t) in Pa, the output is roughly:
p(f,t) ≈ |FFT(x(t) * window)|^2 / window_energy
This ensures the output reflects the true physical power of your signal.
3. Questions about abs(fft(segment)) and dB
You asked: “Does `abs(fft(segment))` refer to the amplitude of the input data? Then where in the function manual is it written that `20*log10(abs(fft(segment)))` is applied?”
- Yes, `abs(fft(segment))` gives the amplitude spectrum of the windowed segment.
- In `pspectrum`, the power spectrum is *already squared*, so when plotting in decibels, it uses `10*log10(p)` instead of 20*log10.
- The reference value (`pref`) for converting to dB isn’t explicitly required in `pspectrum` because it assumes the output is absolute power (Pa²). If you want to define dB relative to a standard reference, you can scale accordingly: `10*log10(p/pref^2)`.
4. Visualization via a .m file
To make this concrete, I prepared a small MATLAB script that:
- Performs the segmentation and windowing manually.
- Computes the FFT and power spectrum for each segment.
- Compares the manually computed spectrogram to `pspectrum`.
pspectrum_demo script
clear; close all; clc;
%% pspectrum_demo.m
% Illustrates how pspectrum processes pressure data
% Sample parameters
fs = 1000; % sample rate in Hz
t = 0:1/fs:1-1/fs; % 1 second
x = 0.1*sin(2*pi*50*t) + 0.05*randn(size(t)); % example signal in Pa
% Parameters for STFT
segmentLength = 128;
overlap = 64;
window = kaiser(segmentLength,6); % Kaiser window similar to pspectrum
% Pre-allocate
nSegments = floor((length(x)-overlap)/(segmentLength-overlap));
p_manual = zeros(segmentLength/2+1, nSegments);
for k = 1:nSegments
idx = (k-1)*(segmentLength-overlap) + (1:segmentLength);
seg = x(idx).*window';
xdft = fft(seg, segmentLength);
p_seg = abs(xdft(1:segmentLength/2+1)).^2 / sum(window.^2);
p_seg(2:end-1) = 2*p_seg(2:end-1); % one-sided scaling
p_manual(:,k) = p_seg;
end
% Time vector for segment centers
t_seg = ((segmentLength/2):(segmentLength-overlap):(length(x)-
segmentLength/2))/fs;
% Plot manual vs pspectrum
figure;
subplot(2,1,1)
imagesc(t_seg, (0:segmentLength/2)*(fs/segmentLength),
10*log10(p_manual))
axis xy
xlabel('Time (s)'); ylabel('Frequency (Hz)');
title('Manual STFT Power (dB)');
subplot(2,1,2)
[p,f,t_ps] = pspectrum(x, fs, 'spectrogram', 'TimeResolution', segmentLength/
fs, 'OverlapPercent', overlap/segmentLength*100);
imagesc(t_ps, f, 10*log10(p))
axis xy
xlabel('Time (s)'); ylabel('Frequency (Hz)');
title('pspectrum Spectrogram (dB)');
The script produces two plots
1. Manual STFT Power (dB) – Shows how each segment contributes to the spectrogram, step by step.
2. pspectrum Spectrogram (dB) – Shows the built-in `pspectrum` result, which matches the manual computation.
This side-by-side comparison helps visualize how the input in Pascals becomes the power in Pa^2 and then optionally converted to decibels.
Plots: Please see attached.
In nutshell,
- output of `pspectrum` represents squared pressure amplitude (Pa^2).
- The computation follows: segmentation → windowing → FFT → magnitude squared → normalization.
- Decibel conversion is `10*log10(p)`, not 20*log10, because it’s already power, not amplitude.
- The `.m` file illustrates the calculations explicitly, making the process transparent.
Hope this helps clarify everything!