sg.m

来自「这里面包含源数多于传感器数的文章和相关源代码。」· M 代码 · 共 45 行

M
45
字号
function [yo,fo,to] = sg(x,nfft,Fs,WINDOW,noverlap)nx = length(x);nwind = length(WINDOW);if nx < nwind    % zero-pad x if it has length less than the window length    x(nwind)=0;  nx=nwind;endx = x(:); % make a column vector for ease laterWINDOW = WINDOW(:); % be consistent with data setncol = fix((nx-noverlap)/(nwind-noverlap));colindex = 1 + (0:(ncol-1))*(nwind-noverlap);rowindex = (1:nwind)';if length(x)<(nwind+colindex(ncol)-1)    x(nwind+colindex(ncol)-1) = 0;   % zero-pad xendy = zeros(nwind,ncol);y(:) = x(rowindex(:,ones(1,ncol))+colindex(ones(nwind,1),:)-1);y = WINDOW(:,ones(1,ncol)).*y;y = fft(y,nfft);if ~any(any(imag(x)))    % x purely real    if rem(nfft,2),    % nfft odd        select = [1:(nfft+1)/2];    else        select = [1:nfft/2+1];    end    y = y(select,:);else    select = 1:nfft;endf = (select - 1)'*Fs/nfft;t = (colindex-1)'/Fs;if nargout == 1,    yo = y;elseif nargout == 2,    yo = y;    fo = f;elseif nargout == 3,    yo = y;    fo = f;    to = t;end

⌨️ 快捷键说明

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