Skip to content

Commit 1ce4666

Browse files
authored
Add files via upload
1 parent 072d274 commit 1ce4666

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Documentation.mlx

57.9 KB
Binary file not shown.

getSamplingPara.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function [t,f] = getSamplingPara(M,fs)
2+
% The function getSamplingPara(M,fs) computes the time and frequency
3+
% vectors based on two inputs: the sampling frequency fs and an integer M
4+
% used to compute the number of time step, which is equal to 2^M.
5+
%
6+
% Inputs:
7+
% M: is a natural number used as the power of 2 and is used to compute the
8+
% number of time step for the simulation.
9+
% fs: Sampling frequency (Hz)
10+
%
11+
% Outputs:
12+
% t: dimensions [1 xN]: time vector (units: s)
13+
% f: dimensions [1 x N/2]: frequency vector (units: s^(-1))
14+
%
15+
% Author: E. Cheynet - UiS - last modified : 25-08-2018
16+
%%
17+
if mod(M,1)~=0 || M<=0, error(' ''M'' should be a natural '); end
18+
N = 2^M; % number of time step
19+
dt = 1/fs;
20+
tmax=dt.*N;
21+
t = (0:N-1)*dt;
22+
fprintf(['Duration of target time series is ',num2str(tmax/3600,3),' hours, i.e. ',num2str(tmax,3),' sec \n\n'])
23+
f0 = 1/tmax; % minimal frequency recorded
24+
fc = fs/2; % Nyquist freq
25+
f = [f0:f0:fc]; % frequency vector
26+
end

randomProcess.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [u,t] = randomProcess(f,S)
2+
%
3+
% [u] = randomProcess(f,S) generates in the time domain a random process
4+
% based on a target power spectral density S, the element of which are
5+
% associated with the frequency vector f.
6+
%
7+
% Inputs:
8+
% f: double-precision array of size [1 x Nfreq] of frequency (in Hz)
9+
% S: double-precision array of size [1 x Nfreq] of the target PSD.
10+
%
11+
% Outputs:
12+
% u: double-precision array of size [N x 1] representing the random process
13+
% t: double-precision array of size [N x 1] representing the time
14+
%
15+
% Author: E. Cheynet - UiB - last modified : 11-06-2020
16+
17+
%% Definitions
18+
Nfreq = numel(f);
19+
dt = 1/(2*f(end));
20+
21+
%% Compute the core spectral matrix A with random phases and the target PSD
22+
A= sqrt(S).*exp(1i*2*pi*rand(1,Nfreq));
23+
A = A(:);
24+
25+
%% Apply the IFFT
26+
Nu = [A(1:Nfreq) ; real(A(Nfreq)); conj(flipud(A(2:Nfreq)))];
27+
u=real(ifft(Nu).*sqrt(Nfreq./(dt)));
28+
29+
t = [0:numel(u)-1].*dt;
30+
31+
end

0 commit comments

Comments
 (0)