Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
stochastic
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
0
Requirements
0
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
Insights
Issues
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
stochasticpublic
stochastic
Commits
3dfad0f4
Commit
3dfad0f4
authored
Jan 22, 2020
by
Philip Roy Charlton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed outdated median PSD files
parent
f57b5d1d
Changes
2
Hide whitespace changes
Inline
Sidebyside
Showing
2 changed files
with
0 additions
and
154 deletions
+0
154
CrossCorr/test/test_medianPSD.m
CrossCorr/test/test_medianPSD.m
+0
29
Utilities/medianPSD.m
Utilities/medianPSD.m
+0
125
No files found.
CrossCorr/test/test_medianPSD.m
deleted
100644 → 0
View file @
f57b5d1d
clear
all
;
nFFT
=
64
;
nOverlap
=
nFFT
/
2
;
%nOverlap = 0;
windowFn
=
ones
(
nFFT
,
1
);
Fs
=
2048.0
;
% How many segments
M
=
1024
;
nx
=
nFFT
+
(
M

1
)
*
(
nFFT

nOverlap
);
x
=
rand
(
nx
,
1
);
tic
;
[
pmed
,
fmed
]
=
medianPSD
(
x
,
windowFn
,
nOverlap
,
nFFT
,
Fs
,
'median'
);
%[pmed, fmed] = medianPSD(x, windowFn, nOverlap, nFFT, Fs, 'mean');
pmed
=
pmed
.'
;
fmed
=
fmed
.'
;
toc
;
tic
;
%[pavg, favg] = pwelch(x, windowFn, nOverlap, nFFT, Fs, 'twosided');
[
pavg
,
favg
]
=
pwelch
(
x
,
windowFn
,
nOverlap
,
nFFT
,
Fs
);
pavg
=
pavg
.'
;
favg
=
favg
.'
;
toc
;
pmed
pavg
\ No newline at end of file
Utilities/medianPSD.m
deleted
100644 → 0
View file @
f57b5d1d
%
% medianPSD  estimate the PSD of a timeseries using the median method
%
% [p, f] = medianPSD(x, windowFn, nOverlap, nFFT, Fs, method)
%
% estimates the power spectral density of x by calculating periodograms
% of overlapping segments in a timesseries x and taking the median value
% in each frequency bin, adjusted by a bias factor. The parameters play the
% same roles as they do in Welch's method implemented in pwelch(), however
% in pwelch() the periodograms are averaged.
%
% The sample median is being used to estimate for the population mean mu of
% the exponential distribution in each frequency bin becuase it is more robust
% to outliers in the PSD of real data. The relationship is
%
% mu = (population median)/ln(2)
%
% however, when using the sample median to estimate mu, the bias factor depends on
% sample size, approaching 1/ln(2) for large samples. This function incorporates
% the bias correction factor calculated in Allen et. al.
%
% https://arxiv.org/abs/grqc/0509116
%
% Another source of bias comes from the fact that the overlapping segments are not
% independent. This can be mitigated by only taking the median of two sets of
% nonoverlapping segments and then taking the average of the two PSDs, as described
% in Allen et. al., but that has not been implemented in this function.
%
% Input:
%
% x  a timeseries
% windfowFn  a window function, which must be a vector of length nFFT
% nOverlap  the number of samples that will overlap in each segment of x
% nFFT  the FFT length used for periodograms
% Fs  the sampling frequency (Hz)
% (optional) method  a string, either 'median' or 'mean', to determine
% which method will be used. For 'mean', the results should be identical
% to those given by pwelch(). The default is 'median'.
%
% Output:
%
% p  the PSD in [x]^2/Hz
% f  bin centre frequencies (Hz)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function
[
p
,
f
]
=
medianPSD
(
x
,
windowFn
,
nOverlap
,
nFFT
,
Fs
,
method
)
% Set default values
if
(
nargin
<
6
)
method
=
'median'
;
end
;
% If there are M segments then the total length is
%
% nx = nFFT + (M1)*(nFFT  nOverlap)
%
% so for length nx we need
%
% M = (nx  nFFT)/(nFFT  nOverlap) + 1
%
% Check arguments
nx
=
length
(
x
);
wn
=
length
(
windowFn
);
if
(
wn
~=
nFFT
)
error
(
'Window length is different to FFT length'
);
end
if
(
nOverlap
<
0
)
error
(
'Overlap is negative'
);
elseif
(
nOverlap
>=
nFFT
)
error
(
'Overlap is >= FFT length'
);
end
;
M
=
ceil
((
nx

nFFT
)/(
nFFT

nOverlap
))
+
1
;
wt
=
norm
(
windowFn
)
.^
2
;
dataIsReal
=
isreal
(
x
);
% Weighting factor for the PSD
if
(
dataIsReal
)
fac
=
2
/(
wt
*
Fs
);
else
fac
=
1
/(
wt
*
Fs
);
end
;
data
=
zeros
(
nFFT
,
M
);
for
k
=
1
:
M
idx
=
(
k

1
)
*
(
nFFT

nOverlap
)
+
1
;
data
(:,
k
)
=
windowFn
.*
x
(
idx
:
idx
+
nFFT

1
);
end
;
data
=
fft
(
data
,
[],
1
);
if
(
dataIsReal
)
data
=
abs
(
data
(
1
:
nFFT
/
2
+
1
,
:))
.^
2
;
else
data
=
abs
(
data
)
.^
2
;
end
;
if
(
strcmp
(
method
,
'median'
))
p
=
(
fac
/
medianBias
(
M
))
*
median
(
data
,
2
);
elseif
(
strcmp
(
method
,
'mean'
))
p
=
fac
*
mean
(
data
,
2
);
else
error
(
'Unknown PSD method'
);
end
;
if
(
dataIsReal
)
% Onesided psd
f
=
(
Fs
/
nFFT
)
*
[
0
:
nFFT
/
2
]
.'
;
p
(
1
)
=
0.5
*
p
(
1
);
p
(
end
)
=
0.5
*
p
(
end
);
else
% Twosided psd
f
=
(
Fs
/
nFFT
)
*
[
0
:
nFFT

1
]
.'
;
end
;
return
;
function
biasFac
=
medianBias
(
M
)
L
=
[
1
:
M
];
biasFac
=
sum
((

1
)
.^
(
L
+
1
)
.*
(
1.
/
L
));
return
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment