/@ess/pwelch.m (d33ce412537ea355d98ada04c6439e2f64197d26) (2527 bytes) (mode 100644) (type blob)
function varargout = pwelch(sys,varargin)
% ds = pwelch(sys,...)
%
% Simulates spectrum of sys using pwelch. If called without output
% arguments the resulting spectra are ploted. The output ds is a dadac
% object containing the simulated (colored) spectra and the white
% noise input (measurement noise). If no parameter structure is given,
% model sample frequency must be specified via optional argument.
%
% Optional arguments (key/value pairs)
% - 'reference': show SN spectrum
% - 'plots': always show plots
% Note that optional arguments have lower precedence than parameter
% structure!
% TODO:
% - change postprocessing!!
% - should this automatically postprocess?
% NOTE:
% - this uses dadac objects!
% PSD can only be calculated for noisy systems
if ~sys.isnoisy()
error('system must be noisy')
end
%% instance dac object
dao = dac.instance();
%% parse input arguments
args = varargin;
nargs = length(args);
% defaults for optional arguments
PLOT_REFERENCE_SPECTRUM = false;
SHOW_PLOTS = false;
% parse rest of varargs
% arguments from pars structure take precedence over these
for ii = 1:2:nargs
switch args{ii}
case 'plots', SHOW_PLOTS = args{ii+1};
case 'reference', PLOT_REFERENCE_SPECTRUM = args{ii+1};
otherwise, warning(['unrecognized argument ' args{ii}])
end
end
%% check input
% check if Ntsim is defined
if isempty(dao.Ntsim)
error('Ntsim must be set')
end
%% local configuration
if ~dao.quiet ddisp = @disp; else ddisp = @() disp(''); end
% initialize PRNG
if dao.prngseed
rand('state', dao.prngseed);
randn('state', dao.prngseed);
end
%% main
if sys.Ts == 0
dt = 1/dao.Fs;
else
dt = sys.Ts;
end
% sample trajectory
xinit = zeros(size(sys.a,1),1);
tvec = (0:dt:(dao.Ntsim-1)*dt)';
% sample measurement + white noise vacuum spectrum (= obsnoise)
simdata = dadac(2,'type','ts');
[simdata(1).yData,~,~,~,simdata(2).yData] = initial(sys,xinit,tvec);
simdata(1).label = 'simulated measurement';
simdata(2).label = 'simulated measurement white noise';
% postprocess white noise if required
% TODO: CHANGE THIS
if dao.postprocess && ~strcmp(dao.postp.method,'none')
bpm = bandpass_model(dao.postp.fdesign,dao.postp.method);
bpm = append(bpm,bpm);
simdata(2).yData = lsim(ss(bpm),simdata(2).yData,tvec);
end
% calculate spectrum
frdata = pwelch(simdata);
%% asign output
% plot spectra
for ii = 1:numel(frdata)
if nargout == 0 || SHOW_PLOTS
pwelchplot(frdata(ii));
else
varargout{1} = frdata;
end
end
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
8 |
8661a74e3bb9b03feca04e50d8efe2bef1b850cb |
.gitattributes |
100644 |
blob |
120 |
cca258db030626db0c4ac1e890cc16eaf252108c |
.gitignore |
040000 |
tree |
- |
5f3320287cc52b8fe00f30aaeb720f4ead041eb4 |
@dac |
040000 |
tree |
- |
3742083c966615ed5cb083eb2a19af4d29d42016 |
@dadac |
040000 |
tree |
- |
9de17412e8ee68e0fe653eeab1b4774a97a895ea |
@daddc |
040000 |
tree |
- |
c3e526da8c47c7fad5294dee214bb0befb2c3fd1 |
@ess |
100644 |
blob |
9760 |
35b8f790dee4b23110889efba1f24197fc8f536e |
README.org |
100644 |
blob |
3791 |
813c5e3910317ab2a1458fad0ffd4afaf8ae50cd |
README.txt |
040000 |
tree |
- |
d28f3f04e3e1eb132dc3e89683f495183012b3b6 |
data_analysis |
040000 |
tree |
- |
eb34931ccd81545efcd60c9adb209065dadc5cd0 |
kalmanfilter |
040000 |
tree |
- |
3043e60b6fbf9136eace3a65fb24c42c544c86ae |
misc |
040000 |
tree |
- |
1dddc962b8ecbf37a997ca89cad3711b3d69cfd8 |
models |
040000 |
tree |
- |
a96e7cf3890bbe98927df60dcb1f69a8fa4382fd |
simulations |
100644 |
blob |
621 |
50214a520c35e3f600fe40789181c708967fcb88 |
startup.m |
040000 |
tree |
- |
86ca0a9d5bf2ede090afb7139b2f2d9d7a0af1db |
statisticstests |
040000 |
tree |
- |
3cf29c8555988b4e2f59b54f29a64facc143697a |
stochasticintegration |
040000 |
tree |
- |
7db02f73f80ee728bfacb21b724ba422ed617df9 |
tests |
040000 |
tree |
- |
d4417b0e6958152f3591a8335f126bf84ff5ae5d |
thirdparty |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/gutc61/Membrane
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/gutc61/Membrane
Clone this repository using git:
git clone git://git.rocketgit.com/user/gutc61/Membrane
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main