sine wave spectrum analysis function

get signal frequency, amplitude, offset voltage, SNR, THD, SND, ENOB of simulation or test output
1.2K Downloads
Updated 11 Apr 2013

View License

% [fsig,amp,vos,snr,thd,sndr,enob,phi]=fft_hann(data, bw_low, bw_high, fs, fig, tit, opt);
% [fsig,amp,vos,snr,thd,sndr,enob,phi]=fft_hann(data, 20, 20e3, 65536, '', 'No title', opt);
% opt=fft_hann(); % return default option.
% fsig: signal frequency
% amp: sig amplitude
% vos: offset voltage
% thd: total harmonic distortion
% sndr: signal to noise and distortion ratio
% enob: efficient number of bits
% phi: signal phase
% data: data to be fft
% bw_low: lowband of inband frequency
% bw_high: highband of inband frequency
% fs : sampling rate
% fig = combination if 'i','f','w','I','F','W', stands for inband fig,
% fullband fig, wave fig, Upper case will generate tit.png file
% tit: title of figure.
% opt: additional options:
% opt.nhd: number of harmonic distortion force to caculate
% opt.nspur: number of spur to caculate
% opt.RL: RL to caculate power;
% opt.win = 'barthannwin','bartlett','blackman','blackmanharris','bohmanwin',
% 'chebwin', 'flattopwin', 'gausswin', 'hamming', 'hann', 'kaiser',
% 'nuttallwin', 'parzenwin', 'rectwin', 'taylorwin', 'triang', 'tukeywin',
% opt.coherent: coherent sampling, minimize skirt
% opt.sig_leakage: when coherent sampling, still caculate as much as possible skirt
% opt.sig_add_span: when coherent sampling, add additional skirt to besides
% of window skirt, no effect when opt.sig_leakage = 1;
% Example:
% x = sin((1:65536)*2*pi*111/2048);
% x = x + 0.001*x.^2 + 0.002*x.^3 + 0.0001*sin([1:65536]*2*pi*31/2048);
% x = x + randn(size(x))*1e-5 + 0.01;
% fft_hann(x,200,20e3,65536,'fiw','title');
% opt=fft_hann();
% opt.coherent=1;
% fft_hann(x,0,20e3,65536,'i','title',opt);
% opt.win = 'rectwin';
% fft_hann(x,0,20e3,65536,'i','title',opt);
% opt.sig_leakage = 1;
% fft_hann(x,0,20e3,65536,'i','title',opt);
% opt.win = 'blackmanharris';
% fft_hann(x,0,20e3,65536,'i','title',opt);

Cite As

liu yongping (2024). sine wave spectrum analysis function (https://www.mathworks.com/matlabcentral/fileexchange/41236-sine-wave-spectrum-analysis-function), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Fourier Analysis and Filtering in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0