Sinusoidal Signal Parameter Estimation from Oscilloscope Data

Publisher:祝福的4号Latest update time:2022-06-23 Source: eefocusKeywords:Oscilloscope Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Experimental requirements

In the second question of the first homework, we practiced writing the expression of the corresponding signal based on the waveform of the signal. But in reality, the signal we observe is often the waveform on the oscilloscope. How can we obtain the mathematical expression of these waveforms?

Oscilloscope for measuring waveforms

Oscilloscope for measuring waveforms

In essence, real signals are random and have no definite mathematical expression. However, in some cases, we know the type of signal in advance, such as a sine wave, but do not know some of the signal parameters, such as amplitude, frequency, and phase. If these parameters are known, we can write the corresponding signal mathematical expression. In this case, recovering the signal from the observed noisy signal waveform belongs to the content of signal parameter estimation.

Some electronic components

Some electronic components

In practical applications, signal parameters are often very important. Here is an example: If you only have a multimeter but no RCL bridge that can measure capacitance and inductance, in order to know the exact capacitance of a capacitor, you can connect the capacitor to be measured in series with a resistor. The resistance value of the resistor can be accurately measured using a multimeter. Use a signal source to generate a sine wave signal and apply it to the RC series circuit. Use an oscilloscope to simultaneously measure the signal of the signal source and the signal after RC voltage division.

Using RC to measure electronic device parameters circuit

Using RC to measure electronic device parameters circuit

According to the circuit principle, we can know that the relationship between the steady-state input and output sinusoidal signals of the above circuit is as follows:

image.pngMeasured circuit and oscilloscope

Measured circuit and oscilloscope

Therefore, the ratio of the amplitudes of the input and output sinusoidal signals is:

image.png

The phase difference between the input and output sinusoidal signals is: θ 

image.png

Therefore, as long as the amplitude or phase and frequency of the two sinusoidal signals U and V can be measured, and the resistance value R1 is known, the capacitance of the capacitor to be measured can be calculated.

image.png

It is known that the resistance nR1.=1009 ohms in the series circuit above. The value of the waveform displayed by the oscilloscope can be obtained by sampling the value at a time interval of fs=10 microseconds, which has been stored in CH12.MAT.

Numerical waveform collected by oscilloscope

Based on the above analysis, please calculate the capacitance of the capacitor nC1 to be tested.


hint:


Read the data in CH12.MAT through the load() command in MATLAB;

ch12(:,1) is the data of V, and ch12(:,2) is the data of U.

Use the MATLAB fit command to estimate the parameters in the data.

f = fit(x,y,‘fourier1’)

The above fit command outputs f(x)=a0+a1cos(xw)+b1sin(xw)

Parameters such as a0, a1, b1, w, etc.

 

Problems with using MATLAB calculations

Calculation steps using MATLAB

Import data and draw waveform graph

load ch12'

t = linspace(0, 1400*10e-6,1400)'

plot(t,ch12(:,1), t, ch12(:, 2))'

Waveform diagram of two measurement data channels

(2) Use MATLAB to calculate the parameters of the sine waveform


f1 = fit(t, ch12(:,1), 'fourier1')'

f2 = fit(t, ch12(:,2), 'fourier1')

f1: a0:119.1442, a1:-1.6132, b1:27.3382, pressure:2481

f2: a0:150.0722, a1:64.1255, b1:43.5524, pressure:2481


2. Problems encountered when using MATLAB calculations

Using the above parameters and the two formulas for calculation, there will be a 1.5-fold difference.

image.png

The associated vector variance is shown below:

Problems with parameters calculated by MATLAB

Problems with parameters calculated by MATLAB

Get data from MATLAB through the clipboard

First, use the following command in the MATLAB command window to copy the CH12 data to the WINDOWS clipboard.


cc(ch12)


Then, the following Python program is used to convert the data on the clipboard into two arrays, corresponding to the collected data of the output and input signals respectively.


pastestr = clipboard.paste().strip('[').strip(']').split(';')

data1=[]

data2=[]


for s in pastestr:

    ss = s.split(' ')

    data1.append(int(ss[0]))

    data2.append(int(ss[1]))


plt.plot(data1)

plt.plot(data2)


tspsave('CH12', ch1=data1, ch2=data2)

printf('a')

plt.show()


Perform function fitting and parameter calculation

Two channel sine waves and their FIT curves

Two channel sine waves and their FIT curves

The program code is as follows:


#!/usr/local/bin/python

# -*- coding: gbk -*-

#============================================================

# TEST2.PY                     -- by Dr. ZhuoQing 2020-02-28

#

# Note:

#============================================================


from headm import *


from scipy.optimize         import leastsq


ch1, ch2 = tspload('CH12', 'ch1', 'ch2')


#------------------------------------------------------------


def make_sine_graph( params, xData):

    """

    take amplitudes A and phases P in form [ C, A0, A1, A2, ..., An, P0, P1,..., Pn ]

    and construct function f = C +A0 sin( w t + P0) + A1 sin( 2 w t + Pn ) + ... + An sin( n w t + Pn )

    and return f( x )

    """

    fr = params[0]

    C = params[1]

    npara = params[2:]

    lp =len (make up)

    amps = npara[ : lp //

    phases = npara[ lp // 2 : ]

    fact = range(1, lp // 2 + 1 )

    return [ sum( [ a * sin( 2 * pi * x * f * fr + p ) for a, p, f in zip( amps, phases, fact ) ]) + C for x in xData ]


def sine_residuals( params , xData, yData):

    yTh = make_sine_graph( params, xData )

    diff = [ y -  yt for y, yt in zip( yData, yTh ) ]

    return diff


def sine_fit_graph( xData, yData, freqGuess=100., dcGuess=100,sineorder = 3 ):

    aStart = sineorder * [ 0 ]

    aStart[0] = max( yData )

    pStart = sineorder * [ 0 ]

    result, _ = leastsq( sine_residuals, [ freqGuess, dcGuess ] + aStart + pStart, args=( xData, yData ) )

    return result


#------------------------------------------------------------



if __name__ == '__main__':


    ch1 = [c / 255  for c in ch1]

    ch2 = [c / 255  for c in ch2]

    t = linspace(0, 1400*10e-6, 1400, endpoint=False)

    result1 = sine_fit_graph(t, ch1, freqGuess=2481/2/pi, dcGuess=0.5, sineorder=1)

    result2 = sine_fit_graph(t, ch2, freqGuess=2481/2/pi, dcGuess=0.5, sineorder=1)


    printf(result1, result2)


    plt.plot(t, make_sine_graph(result1, t))

    plt.plot(t, ch1)

    plt.plot(t, make_sine_graph(result2, t))

    plt.plot(t, ch2)


    tspsave('fitresult', result1=result1, result2=result2)


    printf(tan(result2[3] - result1[3]))$$C = {{tan theta } over {2pi f cdot R}} = {{sqrt {1 - alpha ^2 } } over alpha } cdot {1 over {2pi f cdot R}}$$


    alpha = result1[2] / result2[2]

    printf(sqrt(1-alpha**2)/alpha)



    plt.show()




#------------------------------------------------------------

#        END OF FILE : TEST2.PY

#============================================================


According to the above PYTHON program, recalculate the sine parameters corresponding to the input and output data. The data is as follows, and the estimated parameters obtained are the same as those in MATLAB.


Output waveform fitting sine parameters:

[ 3.95138209e+02 4.67232082e-01 1.07395207e-01 -5.89407332e-02]


Input waveform data to fit sine parameters:

[3.95096587e+02 5.88518451e-01 3.03988482e-01 9.74184940e-01]

tan(theta)=1.6770990200351208

sqrt(1-a**2)/a=2.6480303891707053


Keywords:Oscilloscope Reference address:Sinusoidal Signal Parameter Estimation from Oscilloscope Data

Previous article:Change the image color of the oscilloscope TDS3054D
Next article:Undersampling in the Use of Digital Oscilloscopes

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号