- Windowing Function: 'pspectrum' uses the Kaiser window by default, while 'spectrogram' allows you to specify the windowing function. In your example, you used the Kaiser window for 'spectrogram' as well by using 'kaiser(l, 15.5)'. This ensures that both functions use the same windowing function.
- Window Length: In 'pspectrum', the window length is automatically determined based on the length of the input time series. However, in 'spectrogram', you need to explicitly specify the window length. Make sure that the 'l' value you used in 'kaiser(l, 15.5)' matches the window length used in 'pspectrum.
- Overlap: In 'pspectrum', you specified the overlap percentage as 25%, but in 'spectrogram', you didn't explicitly mention the overlap. The default overlap for 'spectrogram' is 50%. If you want to match the overlap value used in 'pspectrum', you can set the 'overlap' parameter in 'spectrogram' to 25.
- Data Input: 'pspectrum' takes the input as a matrix (prices) with each column representing a separate time series. However, in 'spectrogram', you are passing only the first column of 'prices' using 'prices{:,1}'. Make sure that you are using the correct input data format in 'spectrogram' to match the behaviour of 'pspectrum'.
How can I replay the results I got with the pspectrum function on the spectrogram function?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I used pspectrum to have a spectrogram of a financial time series with the following parameters:
pspectrum(prices,'spectrogram','Leakage',0.5,'OverlapPercent',25);
And I got this nice plot that has been very useful for what I'm trying to analyze:
But I need to have in consideration other windowing functions. Since psectrum only uses the Kaiser window I went to use the Spectrogram function and for starterst I wanted to replicate the results I got but right now my efforts are in vain and the most similar plot I got is this:
spectrogram(prices{:,1},kaiser(l,15.5),45,'power','yaxis');
Is there any consideration or data transformation I'm missing in order to get the same result on both functions?
Any help regarding this, will be very appreciated.
0 Kommentare
Antworten (2)
Sudarsanan A K
am 6 Okt. 2023
Bearbeitet: Sudarsanan A K
am 6 Okt. 2023
Hello Jose,
I understand that you have used the 'pspectrum' function from Signal Processing Toolbox to analyse the signal in the time-frequency domain and obtained the power spectrum by specifying the type of spectral analysis performed by the function as 'spectrogram'. I also note that you are trying to explore other windowing functions by leveraging the flexibility provided by the 'spectrogram' function and you are trying to figure out how you could reproduce the same result as given by the 'pspectrum' function if you use Kaiser window as the windowing function which is the default for 'pspectrum'.
When comparing the results obtained from 'pspectrum' and 'spectrogram' functions for generating spectrograms, there are a few considerations and data transformations you need to keep in mind to achieve similar results:
By considering these factors and ensuring that the windowing function, window length, overlap, and input data are consistent between the two functions, you should be able to obtain similar results using 'spectrogram' as you did with 'pspectrum'.
Also note that when called with no output arguments, both 'pspectrum' and 'spectrogram' plot the spectrogram of the signal in decibels. Include the factor of 2 for one-sided spectrograms ('pspectrum' adds an extra factor of 2 to the spectrogram).
Refer to the following link for better understanding of these aspects with example code: https://mathworks.com/help/signal/ref/pspectrum.html#mw_3a19ac96-d3b7-4e25-a385-3057bd5a887e
Hope this helps you in resolving your issue.
0 Kommentare
Star Strider
am 6 Okt. 2023
You can’t equate the pspectrum and spectrogram function outputs because the units are different. The spectrogram function produces a power spectral density spectrum with units of dB/Hz. The pspectrum function produces a power spectrum with units of dB.
You can actually set your own windows with pspectrum, although you need to deceive it a bit. Use the Leakage parameter and set it (actually β) to 0, (the default is 0.5) creating a rectangular window. Then, choose the window you want, and multiply it by your signal, for example:
signal = signal.*hann(length(signal))
to use an Hann window, and assuming that ‘signal’ is a column vector or that the rows of a matrix correspond to the elements of the independent variable vector (usually time), with different input signals being individual columns of the matrix. Then use ‘signal’ as the input with the name-value pair 'Leakage',0.
Try that.
Example —
Fs = 256; % Sampling Frequency (Hz)
L = 60; % Signal Length (s)
t = linspace(0, L*Fs, L*Fs+1)/Fs; % Time Vector
signal = sum(sin([1:25:100]'*2*pi*t))+randn(size(t))/10; % Signal
figure
plot(t, signal)
grid
xlabel('Time (s)')
ylabel('Amplitude (V)')
title('‘signal’')
figure
pspectrum(signal, Fs, 'spectrogram') % Default Window
figure
pspectrum(signal, Fs, 'spectrogram', 'Leakage',0) % Rectangular Window
figure
pspectrum(signal(:).*hann(length(signal)), Fs, 'spectrogram', 'Leakage',0) % Hann Window
.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Time-Frequency Analysis 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!