pythonmatlabcurve-fittingfrequency-analysis

How can we accurately estimate the frequency of such a signal?


I have a signal whose expression is shown below:

Mathematical expression of the signal

What method can I use to fit this signal accurately when A, B, ω, D,E in the signal are all unknown parameters? In particular, the most critical unknown parameter in there is ω.

The signal looks something like this:

What the signal looks like

How can the value of ω, the most critical of these, be estimated accurately?

I tried MATLAB's lsqcurvefit and nlinfit functions, but the accuracy is hardly satisfactory. Tried extracting ω using FFT and found that the results are not very accurate either.


Solution

  • 1.- The signal supplied in the figure attached to the question clearly shows a single tone + 1 sawtooth.

    This is the supplied kind of a 'screen shot'

    enter image description here

    As long as the tone has enough power to show above the sawtooth spectrum then to estimate the sought frequency of a single tone sufices to just spot the peak of the single tone surrounded by the sawtooth spectrum.

    If the sought tone frequency happens with power below the envelope of the sawtooth, then you have to look for the anomaly along the sawtooth spectrum envelope that otherwise, without a tone, has a smooth 1/k decay with increasing frequency.

    2.- The signal you are analysing is not exactly the one in the supplied expression

    this is the supplied expression of the signal

    enter image description here

    Even if the supplied signal is all you have, one must assume finite power signals, not infinite energy signals, in order to use the Fourier transform.

    Rewording; the signals x1(t)=a*t, x2(t)=a*|t| do not have a Fourier transform either along [-Inf Inf] or [0 Inf] because the integral for the transform to spectrum does not produce anything.

    So we need to time window the signal and therefore the signal to be considered for spectrum analysis is sum of 1 tone and 1 sawtooth.

    Since no tstart tstop or t time reference mentioned I asume one :

    f1=20                       % [Hz] tone frequency
    f2=1                            % [Hz] sawtooth base frequency
    
    if f1>=f2
        dt=1/(50*f1);       % time step [s] seconds
        else
           dt=1/(10*f2);
    end
    Fs=1/dt;                    % [Hz] sampling frequency
    
    tstart=0                    % start time [s]
    tstop=5                     % stop time [s]
    t=[tstart:dt:tstop];        % time reference
    L=numel(t);
    
    A1=.5                       % tone amplitude            
    A2=2                        % sawtooth peak2peak amplitude
    

    If f2*tstop not an integer then either a fraction of a min(f1,f2) should be added or cut last cycle fraction.

    For simplicity I have not included such case where there are cycle tails to deal with.

    % 1 tone
    n2=f2*tstop;           
    x1=A1*sin(2*pi*f1*t);
    
    % sawtooth
    T2=1/f2;
    x20=[0:dt:T2];        % sawtooth base cycle
    x2=A2*repmat(x20(1:end-1),1,n2);
    x2=x2-A2/2;
    y1=x1(1:min(numel(x1),numel(x2)))+x2(1:min(numel(x1),numel(x2)));
    t=t(1:min(numel(x1),numel(x2)));
    
    figure(1);
    plot(t,y1);
    grid on;
    title('Sawtooth + Tone');
    xlabel('t[s]');
    

    So it's clear that the image of the signal supplied in this question is 1 tone and 1 sawtooth.

    enter image description here

    enter image description here

    3.- The supplied image of the signal IS NOT 2 tones and 1 sawtooth

    A signal including 2 tones both on same frequency and 1 sawtooth actually looks as follows :

    A2=A1;                   % A2 is B in the question
    y2=y1+A2*cos(2*pi*f2*t);
    
    figure(2);
    plot(t,y2);
    grid on;
    title('Sawtooth + 2 Tones same amplitude');
    xlabel('t[s]');
    

    enter image description here

    enter image description here

    A2=2*A1;                   
    y2=y1+A2*cos(2*pi*f2*t);
    
    figure(3);
    plot(t,y2);
    grid on;
    title('Sawtooth + 2 Tones 1:2 amplitudes');
    xlabel('t[s]');
    

    enter image description here

    enter image description here

    So it's clear that the image of the signal supplied in the question is 1 tone and 1 sawtooth.

    The time discontinuities, as time signals have been generated, can be solved so there are smooth transitions only. It's not difficult, but laborious, and for the purpose of answering this question, such effort would not add relevant contents.

    4.- Spectrum

    X1=fft(x1);
    XP12=abs(X1/L);
    XP1=XP12(1:floor(L/2)+1);
    XP1(2:end-1)=2*XP1(2:end-1);
    f = Fs*(0:floor(L/2))/L;
    
    figure(4);
    plot(f,XP1);
    grid on;
    title('X1(f)=TF(x1(t)) single tone : single side spectrum');
    xlabel('f');
    

    enter image description here

    enter image description here

    In contrast to single tones, sawtooths have populated spectrums, noise and interference aside

    enter image description here

    enter image description here

    Y1=fft(y1);
    YP12=abs(Y1/L);
    YP1=YP12(1:floor(L/2)+1);
    YP1(2:end-1)=2*YP1(2:end-1);
    f = Fs*(0:floor(L/2))/L;
    
    figure(6);
    ax6=gca
    plot(ax6,f,YP1);
    grid(ax6,'on');
    title(ax6,'Y1(f)=TF(y1(t)) tone + sawtooth : single side spectrum');
    xlabel(ax6,'f');
    hold(ax6,'on')
    

    enter image description here

    5.- References to Sawtooth signal basics:

    We can review sawtooth signal basics in for instance:

    https://mathworld.wolfram.com/FourierSeriesSawtoothWave.html

    and

    https://en.wikipedia.org/wiki/Sawtooth_wave

    6.- Sawtooth signal spectrum envelope

    T2 is the sawtooth base cycle.

    Remove the DC constant if the sawtooth was been time defined as with no DC.

    A2 is the sawtooth amplitude WITH DC as I have initially defined it.

    The null DC sawtooth, has amplitude A2/2.

    The envelope of the sawtooth SIGNAL (NOT POWER) spectrum is 1/(pi*k) but this does not include Fs and L :

    k1=[0:1:numel(f)-1];

    % sawtooth signal (NOT POWER) spectrum envelope
    S=2*L/Fs*A2/pi*1./(k1);       % double the signal (NOT POWER) envelope because it's 1-side spectrum
    plot(ax6,f,S,'Color','r','LineWidth',2)
    

    enter image description here

    enter image description here

    Comments

    Note there's no DC because the tone is sin and I have removed any sawtooth DC.

    For 2 tones, since both would be on the same frequency the amplitude spectrum would be similar.

    If you would like to see how to catch weak tones cluttered with a sawtooth signal please post another question.