测量的锯齿期

时间:2016-03-07 00:34:03

标签: matlab octave period measures

我有一系列2D测量(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))))

但它没有用,或者至少它给了我一个我知道的答案。

绘制数据的示例:

enter image description here

我也尝试过以下方法 - 应该工作 - 但它并没有让我知道我接近正确的答案。我的代码可能有些简单和错误。什么?

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

1 个答案:

答案 0 :(得分:1)

老帖子,但我以为我提供了2美分的价值。我认为有两种合理的方法可以做到这一点:

  1. 执行傅立叶变换并计算基本
  2. 将相位,周期,幅度和偏移曲线拟合到理想的方波。
  3. 由于锯齿波的不连续性,给定曲线拟合可能很困难,因此我建议使用傅里叶变换。下面的自包含示例:

    f_s = 10;             # Sampling freq. in Hz
    record_length = 1000; # length of recording in sec.
    
    % Create noisy saw-tooth wave, with known period and phase
    saw_period = 50;
    saw_phase = 10;
    t = (1/f_s):(1/f_s):record_length;
    saw_function = @(t) mod((t-saw_phase)*(2*pi/saw_period), 2*pi) - pi;
    
    noise_lvl = 2.0;
    saw_wave = saw_function(t) + noise_lvl*randn(size(t));
    num_tsteps = length(t);
    
    % Plot time-series data
    figure();
    plot(t, saw_wave, '*r', t, saw_function(t));
    xlabel('Time [s]');
    ylabel('Measurement');
    legend('measurements', 'ideal');
    
    % Perform fast-Fourier transform (and plot it)
    dft = fft(saw_wave);
    freq = 0:(f_s/length(saw_wave)):(f_s/2);
    dft = dft(1:(length(saw_wave)/2+1));
    
    figure();
    plot(freq, abs(dft));
    xlabel('Freqency [Hz]');
    ylabel('FFT of Measurement');
    
    % Estimate fundamental frequency:
    [~, idx] = max(abs(dft));
    peak_f = abs(freq(idx));
    peak_period = 1/peak_f;
    disp(strcat('Estimated period [s]: ', num2str(peak_period)))
    

    输出几个图表,以及锯齿波的估计周期。您可以使用大量的噪音,并确保它正确地获得50秒的时间,直到噪音非常高。

    Estimated period [s]: 50