welchspectrum.m

来自「求一个给的的信号输入的平均频率的matlab程序」· M 代码 · 共 40 行

M
40
字号
function wSuy = welchspectrum(y,u,Nsegment)
%
% function wSyu = welchspectrum(u,y,Nsegment)
%
% segments the data in Nsegment and calculates the spectrum averaged over
% the segments
% version: February 20, 2008

N     = length(u);
[m,n] = size(u);

% u and y should be vectors (not an array)
if m > n
    u = u.';
    y = y.';
end

% Number of samples per segment
Nd  = floor(N/Nsegment);

% data should an integer number of segments 
u   = u(1:Nd*Nsegment);
y   = y(1:Nd*Nsegment);

%reshape data, fft, and take the average
u   = reshape(u,Nd,Nsegment);
y   = reshape(y,Nd,Nsegment);
U   = fft(u);
Y   = fft(y);
Suy = 1/Nd * conj(U) .* Y;
wSuy = mean(Suy,2).';

% If the input was a column vector, out needs to be transposed
if m > n
    wSuy = wSuy.';
end



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?