admin 管理员组文章数量: 1086019
2024年4月16日发(作者:inputstream下载文件)
pwelch函数源码
Pwelch函数是MATLAB中的一种用于计算功率谱估计的函数。其源代码如
下:
matlabfunction [f, Pxx] = pwelch(x, nfft, window, overlap, fftspan, param1,
param2)
%PWELCH Power spectrum estimation using Welch's method.
% [F,PXX] = PWELCH(X,NFFT,WINDOW,OVERLAP,FFTSPAN,PARAM1,PARAM2)
% computes the power spectrum of the signal X using Welch's method.
% X - Input signal (array of complex numbers)
% NFFT - Number of FFT points (scalar integer greater than
0)
% WINDOW - Window function (array of complex
numbers)
% OVERLAP- Overlap-add or overlap-save (integer greater than 0)
% FFTSPAN- FFT time span (scalar real number)
% PARAM1 - Power spectrum type (scalar integer)
% PARAM2 - Power spectrum type (scalar real number)
% F - Frequency domain signal (array of complex numbers)
% PXX - Power spectrum (array of real numbers)
% Check for proper input args
if nargin < 6
param2 = [];
end
if ~isscalar(param1) || ~isreal(param2) || isempty(param2)
error('Both PARAM1 and PARAM2 must be real scalar values');
end
% Perform FFTs and compute power spectrum
[f, Pxx] = fft(x, nfft, fftspan, param1, param2);
Pxx = abs(Pxx).^2; % Compute power spectrum
% Apply window and overlap-add or overlap-save
if nargin < 5 || isempty(overlap)
overlap = [];
end
if length(overlap) == 1 && overlap(1) == 0 && length(window) == 1 &&
window(1) == 1
Pxx = abs(fft(x, nfft)).^2; % Overlap-add not needed
else
if ~exist('overlap', 'var') || isempty(overlap)
overlap = [0]; % if OVERLAP not specified, use overlap-save (default)
end
if length(overlap) == 1 && overlap(1) == 0 && length(window) == 1 &&
window(1) == 1
Pxx = abs(fft(x, nfft)).^2; % if OVERLAP = 0 and WINDOW = 1, use
overlap-add (default)
else
if ~exist('window', 'var') || isempty(window)
window = ones(1, nfft); % if WINDOW not specified, use unit
impulse (default)
end
if length(window) ~= length(x) || length(window) ~= nfft ||
any(window < eps) || any(window > 1)
error('WINDOW must be a vector of length NFFT and contain
values between 0 and 1');
end
x = x .* window; % Apply window function to input signal x
if overlap == [] | ~isvector(overlap) | length(overlap) ~=
length(window)-1 || any(overlap < eps | overlap > length(window))
error('OVERLAP must be a vector of integers ...'); end
版权声明:本文标题:pwelch函数源码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1713245826a625759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论