目录
1 概述
2 运行结果
3 参考文献
4 Matlab代码
谐波是指对周期性非正弦交流量进行傅里叶级数分解所得到的大于基波频率整数倍的各次分量,通常称为高次谐波,而基波是指其频率与工频(50Hz)相同的分量。本代码尝试在Matlab中使用傅里叶级数展开从谐波的和中绘制一个方波。
[1]肖勇,赵伟,黄松岭.基于离散傅里叶级数的非同步采样下谐波功率测量算法[J].电工技术学报,2018,33(07):1570-1578.DOI:10.19595/j.cnki.1000-6753.tces.170130.
主函数部分代码:
% USAGE: square_wave_project ([T, [num, [max, [min, [start, [state]]]]]])
function [] = square_wave_project (varargin)
% if there is more coputing power, increase these
periods = 3; % number of periods to display
points = 500; % number of points each second, recommend at least 500
% get the default values for unstated options
[T, num, max, min, start, state] = get_default_options(varargin)
t = linspace(start, start+periods*T, points*periods*T);
[f, aN, bN, cos_component, sin_component] = make_square_wave(T, num, max, min, start, state, t);
visualization(f, t, aN, bN, 1/T, cos_component, sin_component);
end
function [T, num, max, min, start, state] = get_default_options (varargin)
T_default = 1; % period
num_default = 100; % number of addends to compute
max_default = 5; % high value
min_default = -5; % low value
start_default = 0; % starting time
state_default = 0; % starting state (1 or 0)
% only want 6 optional inputs at most
numvarargs = length(varargin{1});
if numvarargs > 6
error('square_wave_project:TooManyInputs', ...
'requires at most 6 optional inputs');
end