How to specify number of samples used to calculate the power spectrum using function pspectrum?
2 views (last 30 days)
Show older comments
I have a time signal (sig20) of 65433 data points (N) that i read from an excel file, (i dont know if i can attach the file). The signal was measured with sampling frequency Fs of 31.25 kHz.
When i try to calculate power spectrum using :
Ts=3.2e-5;
Fs=1/Ts;
sig20=readtimetable("20.csv","TimeStep",seconds(Ts),"ReadVariableNames",true)
sig20.Properties.StartTime=seconds(-1);
[p(:,1),freq]=pspectrum(sig20.v0_8, Fs);
, it returns freq of size [4096x 1] and maximum frequency of 15.625 kHz. This means it has used 4096*2 = 8192 samples only which is quite less than the amount of data i have. I know this has been selected for practicality reasons. However, how to specify it to use for example 65432 data points (the nearest even number from my number of samples) in order to get the best frequency resolution?
0 Comments
Answers (1)
Yukthi S
on 16 Feb 2024
Edited: Rena Berman
on 16 Jul 2024
Hi Shehab
I figure out that you were not able to use all the 65,432 data points to plot the power spectrum.
You can try including “FrequencyResolution” in the input arguments of “pspectrum” to explicitly specify the number of data points to be used while plotting the spectrum.
You can modify the code as below:
[p(:,1), freq] = pspectrum(sig20.v0_8, Fs, 'FrequencyResolution', freqResolution);
You can refer to the following MathWorks documentation link for more insights on “FrequencyResolution”:https://www.mathworks.com/help/releases/R2021a/signal/ref/pspectrum.html?searchHighlight=pspectrum%20%26quot%3B%2Cfrequency%26quot%3B%20resolution&s_tid=doc_srchtitle#d123e133022:~:text=%CF%80%20rad/sample.-,%27FrequencyResolution%27,-%E2%80%94%20Frequency%20resolution
0 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!