我有一系列二維測量結果(x軸上的時間),繪製成非光滑(但非常好)的鋸齒波。在理想的世界中,數據點會形成完美的鋸齒波(在任一端都有部分振幅數據點)。有沒有使用OCTAVE/MATLAB來計算波的(平均)週期的方法?我嘗試使用公式維基百科(Sawtooth_wave)鋸齒:測量鋸齒的週期
P = mean(time.*pi./acot(tan(y./4))), -pi < y < +pi
也試過:
P = mean(abs(time.*pi./acot(tan(y./4))))
,但它沒有工作,或至少它給了我,我知道的答案了。
繪製數據的一個例子:
我也嘗試下面的方法 - 應該工作 - 但它不給我我所知道的是接近正確的答案。可能是我的代碼簡單和錯誤。什麼?
slopes = diff(y)./diff(x); % form vector of slopes for each two adjacent points
for n = 1:length(diff(y)) % delete slope of any two points that form the 'cliff'
if abs(diff(y(n,1))) > pi
slopes(n,:) = [];
end
end
P = median((2*pi)./slopes); % Amplitude is 2*pi
計數過零點? –
理論上是的,但y中的度量通常不是那麼精確。 – user46655
從來沒有爲X軸 – user46655