-1

找出作为 n 函数的误差,其中误差定义为傅立叶级数 (vF (t)) 的电压与理想函数 (v(t)) 的值之间的差值,归一化为最大幅度(Vm):

我在 Vm = 1 V 的地方得到这个提示。这一行下面是我编写的代码。

我正在尝试编写一个函数来解决这个问题:绘制 n=3、n=5、n=10 和 n=50 的误差与时间。(10点)。看起来我做错了什么?


clc;
close all;
clear all;

% define the signal parameters
Vm = 1;
T = 1;
w0 = 2*pi/T;

% define the symbolic variables
syms n t;

% define the signal
v1 = Vm*sin(4*pi*t/T);
v2 = 2*Vm*sin(4*pi*t/T);

% evaluate the fourier series integral
an1 = 2/T*int(v1*cos(n*w0*t),0,T/2) + 2/T*int(v2*cos(n*w0*t),T/2,T);
bn1 = 2/T*int(v1*sin(n*w0*t),0,T/2) + 2/T*int(v2*sin(n*w0*t),T/2,T);
a0 = 1/T*int(v1,0,T/2) + 1/T*int(v2,T/2,T);

% obtain C by substituting n in c[n]
nmax = 100;
n = 1:nmax;
a = subs(an1);
b = subs(bn1);


% define the time vector
ts = 1e-2; % ts is sampling the
t = 0:ts:3*T-ts;

% directly plot the signal x(t)
t1 = 0:ts:T-ts;
v1 = Vm*sin(4*pi*t1/T).*(t1<=T/2);
v2 = 2*Vm*sin(4*pi*t1/T).*(t1>T/2).*(t1<T);
v = v1+v2;
x = repmat(v,1,3);

% Now fourier series reconstruction
N = [3];

for p = 1:length(N)
for i = 1:length(t)
for k = N(p)  
x(k,i) = a(k)*cos(k*w0*t(i)) + b(k)*sin(k*w0*t(i));
end
% y(k,i) = a0+sum(x(:,i)); % Add DC term
end

end

z = a0 + sum(x);

figure(1);
plot(t,z);

%Percent error
function [per_error] = percent_error(measured, actual)
per_error = abs(( (measured - actual) ./ 1) * 100);
end
4

1 回答 1

0

论坛的目的是帮助解决特定的技术问题,而不是做你的功课。

于 2019-11-15T08:18:43.463 回答