用Matlab将锯齿波进行指数级傅立叶级数展开
时间: 2024-02-11 17:09:01 浏览: 87
傅立叶级数展开 matlab.doc
5星 · 资源好评率100%
在Matlab中,我们可以使用“exp”函数和傅立叶级数公式来将锯齿波进行指数级傅立叶级数展开。具体步骤如下:
1.定义锯齿波函数:
```matlab
function y = sawtooth_wave(t, T)
% t为时间向量,T为锯齿波周期
y = (t/T) - floor(t/T + 1/2);
end
```
2.设置展开参数:
```matlab
T = 1;
N = 10; % 展开项数
```
3.计算傅立叶级数系数:
```matlab
n = -N:N;
c = 1./(2*pi*1i*n) .* (exp(-1i*2*pi*n*T/2) - 1);
```
4.计算指数级傅立叶级数展开:
```matlab
t = linspace(-3*T, 3*T, 1000);
y = zeros(size(t));
for nn = 1:length(n)
y = y + c(nn)*exp(1i*2*pi*n(nn)*t/T);
end
```
5.绘制锯齿波和展开结果:
```matlab
% 绘制锯齿波
figure;
plot(t, sawtooth_wave(t, T), 'LineWidth', 2);
hold on;
% 绘制展开结果
plot(t, real(y), 'LineWidth', 2);
grid on;
xlabel('Time (s)');
ylabel('Amplitude');
legend('Original Signal', ['Exp Fourier Series, N = ' num2str(N)]);
```
完整代码如下:
```matlab
function y = sawtooth_wave(t, T)
% t为时间向量,T为锯齿波周期
y = (t/T) - floor(t/T + 1/2);
end
T = 1;
N = 10; % 展开项数
n = -N:N;
c = 1./(2*pi*1i*n) .* (exp(-1i*2*pi*n*T/2) - 1);
t = linspace(-3*T, 3*T, 1000);
y = zeros(size(t));
for nn = 1:length(n)
y = y + c(nn)*exp(1i*2*pi*n(nn)*t/T);
end
figure;
plot(t, sawtooth_wave(t, T), 'LineWidth', 2);
hold on;
plot(t, real(y), 'LineWidth', 2);
grid on;
xlabel('Time (s)');
ylabel('Amplitude');
legend('Original Signal', ['Exp Fourier Series, N = ' num2str(N)]);
```
阅读全文