TimeseriesFromPSD(S​xx, fs, T, plot_on)

Versione 1.5.0.0 (4,94 KB) da Michael
Create timeseries from a given double-sided PSD
1,6K download
Aggiornato 29 giu 2015

Visualizza la licenza

Create one realization of a timeseries from a given double-sided PSD, Sxx
NOTE: Since we don't have phase information, the original timeseries is
not recoverable. We can, however, create a random timeseries that has the
same statistical characteristics as the original timeseries.
Steps:
Create perfect white noise by generating random phase in the frequency
domain, and then multiply it by your PSD. Then transfer it to the time
domain...Take note that MATLAB expects the conjugate symmetric part of
the spectrum to be the second half of the array.

INPUTS
Sxx - Double-sided power spectral density in the expected MATLAB
order e.g. [wavePSD_positiveFreq wavePSD_negativeFreq]

fs - Sample rate of the output timeseries [samples/sec]

T - Desired length of the output timeseries [seconds]

OUTPUTS
timeseries - Generated timeseries

time - Time vector corresponding to timeseries generated

EXAMPLE
T = 100; % Length of timeseries
fs = 25; % Sample rate of timeseries
f0 = 2; % For this example, just do a tone

% Build PSD of a single tone in this example
rmsLevel = 1; % RMS level of tone
df = 1/T;
GxxMag = ((rmsLevel^2)/df); % Single-Sided Power spectrum magnitude
SxxMag = GxxMag/2; % Double-sided Power spectrum magnitude
PSD_DoubleSided = zeros(T*fs, 1);
PSD_DoubleSided(f0*T+1) = SxxMag;
PSD_DoubleSided(end-f0*T+1) = SxxMag;

[timeseries, time] = TimeseriesFromPSD(PSD_DoubleSided, fs, T); % Run!

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright Mike Rudolph, 2014
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Last modified: July 29, 2014
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cita come

Michael (2024). TimeseriesFromPSD(Sxx, fs, T, plot_on) (https://www.mathworks.com/matlabcentral/fileexchange/47342-timeseriesfrompsd-sxx-fs-t-plot_on), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2014a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Fourier Analysis and Filtering in Help Center e MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.5.0.0

Version 2: resample Sxx based on input T

1.4.0.0

Added example in code, and made extra sure everything checks out based on what you input, and cleaned up comments.

1.3.0.0

Modified code and comments to make it easier to follow. Corrected some of the scaling factors so that generated timeseries is in the proper units and is scaled correctly.

1.2.0.0

Make sure you get back to original units in time domain. Take note the beginning and end will have ringing, an artifact of the IFFT.

1.1.0.0

Fixed error to PSD input definition.

1.0.0.0