创建具有相移的周期性三角波形
creating a perodic triangle waveform with phase shift
我可以通过改变变量 freq
创建一个周期性的三角波形,但是我怎样才能让三角波形从 t=0
开始,像正弦波一样向上倾斜。我试图找出类似于正弦波方程 但基本上是三角波形的东西。有这样的东西吗?
其中:
代码如下:
t=linspace(0,2*pi,1000);
freq=2; %how many in 1 sec
A = 1; % amplitude
T = 2*pi/freq; % period of the signal
% triangle
figure(1);
triangle = (mod(t * A / T, A) > 0.5).*mod(t * A / T, A) + (mod(t * A / T, A) <= 0.5).*(1 - mod(t * A / T, A));
triangle = 2*triangle - 1.5;
plot(t, triangle);
title('triangle');
PS:我使用的是 octave 4.0,它类似于 matlab。
你也知道sawtooth
信号处理工具箱吗?看看 here 一个很好的例子。
--> 如果你想让它开始向下,就把它倒过来。如果你想让它围绕 y=0 对称,那么简单 substract/add 一个偏移量。
这是最终代码,以防其他人需要这样做
clear all
figure(1);
freq=2
fs=1000;
t2=linspace(0,2*pi,fs);
phase_shift=pi/2; %phase shift
tri_w_phase=sawtooth(freq*t2+phase_shift,.5);
plot(t2,tri_w_phase)
title('triangle with freq edit and phase shift');
我可以通过改变变量 freq
创建一个周期性的三角波形,但是我怎样才能让三角波形从 t=0
开始,像正弦波一样向上倾斜。我试图找出类似于正弦波方程
其中:
代码如下:
t=linspace(0,2*pi,1000);
freq=2; %how many in 1 sec
A = 1; % amplitude
T = 2*pi/freq; % period of the signal
% triangle
figure(1);
triangle = (mod(t * A / T, A) > 0.5).*mod(t * A / T, A) + (mod(t * A / T, A) <= 0.5).*(1 - mod(t * A / T, A));
triangle = 2*triangle - 1.5;
plot(t, triangle);
title('triangle');
PS:我使用的是 octave 4.0,它类似于 matlab。
你也知道sawtooth
信号处理工具箱吗?看看 here 一个很好的例子。
--> 如果你想让它开始向下,就把它倒过来。如果你想让它围绕 y=0 对称,那么简单 substract/add 一个偏移量。
这是最终代码,以防其他人需要这样做
clear all
figure(1);
freq=2
fs=1000;
t2=linspace(0,2*pi,fs);
phase_shift=pi/2; %phase shift
tri_w_phase=sawtooth(freq*t2+phase_shift,.5);
plot(t2,tri_w_phase)
title('triangle with freq edit and phase shift');