# How do I interpret output data from spectrogram function

조회 수: 14 (최근 30일)
Ryan Troha 2021년 6월 2일
답변: Sudarsanan A K 2024년 4월 29일
I have a dataset of 57794048 samples with a sampling rate of 32000 Hz. I would like to extract power data at each sample point using the spectrogram function. I've tried using the code below with X being the dataset. I end up with s being 8388609 x 1 complex double, t being 1 x 8 double, and f being 8388609 x 1 double. Can someone help me interpret this output? Why am I only getting 8 timepoints?
fs = 32000;
[s,f,t] = spectrogram(X,[],[],[],fs);

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

### 답변 (1개)

Sudarsanan A K 2024년 4월 29일
Hello Ryan,
The output you are observing from the "spectrogram" function is as expected due to how the function processes the input signal:
• "s" (STFT Matrix): The complex matrix "s" represents the power spectral density of each signal segment. Its size is influenced by the FFT length, and the parameters specified in the "spectrogram" function call.
• "t" (Time Vector): The 1 x 8 dimension for "t" indicates that the spectrogram computed the signal's power spectral density at 8 distinct time points. This is a direct result of how the input signal is divided into overlapping segments by the function, with the exact number of time points depending on the signal's length and the specified parameters.
• "f" (Frequency Vector): This vector lists the frequencies at which the spectrogram was computed, with its size determined by the FFT length and the parameters used in the function.
If your aim is to extract power data for each sample point across the entire frequency spectrum without segmenting the signal, the "periodogram" function is more suitable for your needs. Unlike the "spectrogram", which analyzes the signal in segments, the "periodogram" computes the Power Spectral Density (PSD) for the entire signal:
fs = 32000;
[P,f] = periodogram(X, [], [], fs);
Here, "P" gives the power spectral density at each frequency "f", providing a comprehensive view of the signal's power distribution across frequencies without dividing it into segments.
You can also use "pwelch" function for estimating the power spectral density of a signal, which provides more control over the window function, overlap, and other parameters compared to the "periodogram" function. It also automatically handles the windowing and averaging of the segments, making it a convenient choice for power spectral density estimation. Please refer to the respective documentations given below for further details:
I hope this helps!

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

### 카테고리

Help CenterFile Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by