Lab descriptions - PowerPoint PPT Presentation

About This Presentation
Title:

Lab descriptions

Description:

Lab descriptions Lab: Pitch tuner Lab: Self balancing platform Labs: pitch tuner and self balancing platform (v.5b) * – PowerPoint PPT presentation

Number of Views:135
Avg rating:3.0/5.0
Slides: 34
Provided by: khwong
Category:

less

Transcript and Presenter's Notes

Title: Lab descriptions


1
Lab descriptions
  • Lab Pitch tuner
  • Lab Self balancing platform

2
Laboratory 1
  • A simple Pitch tuner

3
Objectives
  • To lean how to interface analogue signals to
    digital systems
  • To learn how to process audio signals in embedded
    systems.
  • Aim
  • To develop a pitch tuner using an embedded system.

4
Signal processing steps
  • Capture signal by microphone
  • Amplify the signal
  • Feed to ADC of AMR7 micro.
  • Convert to digital , find autocorrelation coeff.
  • Find pitch

5
Hardware system

RS232
Mic amp
ADC input ARM7
PC for display result
Mic
6
Amplifier
  • What is the best bias voltage at pin3(non-invert.
    input) ?
  • Condenser MIC output impedance is 75 Ohms, why
    this circuit is not a good design. How to correct
    it?
  • Hint Input1KHZ, find impedance of C1 and input
    of the amp.
  • Solution C1gt1uF, R21K, V3 100K(VR), use ,
    one VR to replace VR1,2. Discuss why?

7
Software Algorithm to find period1/frequency
8
Pitch Estimation Method ACF (Autocorrelation
function)
  • Autocorrelation function (ACF)

Symmetrical on both side
m
9
What is Auto-correlation, R(m)?
  • E.g.
  • x1 5 7 1 4
  • N5,
  • R(0)x(0)x(0)x(1)x(1)x(2)x2x(3)x(3)x(4)x
    (4)
  • R(0) (1 2549116)92
  • R(1)x(0)x(1)x(1)x(2)x(2)x(3)x(3)x(4)
  • x1 5 7 1 4
  • 1 5 7 1 4
  • (5 35 7 4)51
  • And so on
  • R92.0000 51.0000 40.0000 21.0000
    4.0000

10
Example. First, what is auto-correlation?
  • matlab code
  • fs1
  • x1 5 7 1 4 8 6 2 4 9 3 '
  • auto_corr_xxcorr(x) auto-correlation
  • figure(1), clf
  • subplot(2,1,1),plot(x)
  • grid on, grid(gca,'minor'), hold on
  • subplot(2,1,2),plot(auto_corr_x)
  • grid on, grid(gca,'minor')
  • pks,locs findpeaks(auto_corr_x)
  • mm,peak1_indmax(pks)
  • 'peak value1 at location'
  • pks(peak1_ind) peak
  • locs (peak1_ind) location
  • 'peak value2 at location'
  • pks(peak1_ind1)peask next to the top peak
  • locs (peak1_ind1) location
  • periodlocs(peak1_ind1)-locs(peak1_ind)
  • pitch_Hzfs/period display pitch in Hz

Xt
t
Auto_correlation(xt)
R(m)
  • We only look at positive n
  • Gap between two peaks is 4, so period of X is
    around 4

Ans ??
11
autocorrelation
  • When a segment of a signal is correlated with
    itself, the distance (-Lag_time_in_samples)
    between the positions of the maximum and the
    second maximum correlation is defined as the
    fundamental period (1/pitch_frequency) of the
    signal.

To simplify matter, only the positive j is
plotted, -ve j is a just a mirror image.
12
Then the fundamental frequency can be calculated
as
  • Then the fundamental frequency can be calculated
    as
  • Usually assume j10, then

13
Testing a real sound A5_flute 880Hz, (sampling at
fs44100Hz)
  • testing a real sound , matlab code
  • x1 3 7 2 1 9 3 1 8 ,
  • xx,fs,nbitswavread('c\sounds\A5_flute.wav')
  • sound(x,fs)fs44100Hz,
  • fs sampling freuqncy
  • start10000 pitch a fram around t10000
  • length512
  • xxx(startstartlength)
  • auto_corr_xxcorr(x) auto-correlation
  • figure(1), clf
  • subplot(2,1,1),plot(x)
  • title(' one frame of the sound A5-flute880Hz')
  • grid on, grid(gca,'minor'), hold on
  • subplot(2,1,2),plot(auto_corr_x)
  • title('cross correlation result')
  • grid on, grid(gca,'minor')
  • pks,locs findpeaks(auto_corr_x)
  • mm,peak1_indmax(pks)
  • 'peak value1 at location'

(xt)
Auto_correlation(xt)
2 peaks at t513, 563
Use sort( ) in matlab to find the two peaks, The
gap between 2 peaks is dt563-51350, hence
frequency is fs/dt44100/50882 Hz. Note Pitch
of a flute sound played by a human may not be too
stable.

14
Matlab example 1
  • a1 3 9 3 2 3 8 3 2 ,
  • r(xcorr(a)) ,round (r)
  • Rr(jtime lag)
  • r 2 9 35 60 96 72 86 123
    190 123 86 72 96 60 35 9 17 2
  • Exercise
  • Verify by hand the first 3 (r j ) elements
    after the signal overlapped with itself.

15
Matlab Example2a1 3 9 3 2 3 8 3 2
,r(xcorr(a)) figure(1),clf,subplot(2,1,1)plot(
a),subplot(2,1,2)plot(r)
Data (a)
Period4,
Pick 2 peaks and measure period
Auto Corr. Xcorr (r)
The middle is the peak
16
Since correlation is mirrored at the lag time
(j0) when the signal overlapped with itself
  • Only positive time lag is considered
  • Fundamental Periodj2

Auto correlation R(j)
Rthe_max (j1) Rsecond_max (j2)
Lag Time j in samples
j2
j10
17
Matlab Example3ysin wave of 440 Hz
  • dt0.0001
  • time0dt2
  • freq440
  • nu2.0pifreq
  • ysin(nutime) angular freq. (sin wave of 440
    Hz)
  • r(xcorr(y))
  • figure(2) , clf, subplot(2,1,1), plot(time,y)
  • axis (0 0.01 -1 1)
  • subplot(2,1,2), plot(time(1100),r(1100))

18
Matlab Example3In fact any two peaks will give
you the answersine wave of 440
Hz,period0.0091-0.0068 (by inspection between 2
peaks)freq1/period434.7Hz
input Data (y)
Auto Corr. (r)
0.0068 0.0091
19
Conclusion
  • Studied a method of measuring the pitch of an
    audio sound.

20
Laboratory 2
  • A self balancing platform

21
Objectives
  • 1. Objectives
  • To lean how to interface a direct current (DC)
    output sensor to an microcontroller
  • To learn how to implement a ProportionalIntegral
    Derivative PID feed back control system.
  • 2. Aim
  • To develop a self-balancing platform using an
    embedded system.
  • Reference http//www.cse.cuhk.edu.hk/7Ekhwong/ce
    g3480/PID_DC_motor_Control08.ppt

22
control methodPID (proportional-integral-derivat
ive) control
Required position0
Integral control I (deltal) dt

error term e0-tmpl deltal
0
PWM generator
Proportional control P(deltal)
-
sum
tmpl
Left_pwm

Derivative control Dd(deltal)/dt
Position Sensor (tmpl)
23
The experimental setup

video
24
Fig. 1b.Block Diagram of the Self-balancing
platform

25
Fig. 2 Two channels DC amplifier circuit

26
Fig. 3 (a) Top View of the Accelerometer , (b)
the sensor attached to the bottom of the platform

x-axis
y-axis
In the arm mcu we set 15000 read_sensor(1.5V)
27
Special techniques
  • MIDL is the mid set point value for X-axis
  • Use integer int to simulate floating point
  • Multiply the value by x and divide it by x
    afterwards, (e.g. x200 in our example)
  • tmpl is the tilt position measurement
  • edeltal (tmpl - (MIDL200)) / 200
  • Derivative is de(t) / dt e (current ) e
    (previous)
  • diffl deltal lastl
  • Integration is e dt e (current) e (previous)
  • accul deltal/200 //arbitrary set to divide by
    200, Dead-band (see next page)

28
Dead band
  • Dead-band A Dead-band (sometimes called a
    neutral zone) is an area of a signal range or
    band where no action occurs only enable motor
    when tile angle outside /-? degrees (?0.1
    degrees). http//en.wikipedia.org/wiki/Dead-band

Dead-band
29
Algorithm of left motor (core loop in timer
IRQ_exception) 500Hz
  • void __irq IRQ_Exception()
  • tmpl read_sensor(0) // read X-axis value
  • //putint(tmpl) // display on terminal
  • // print(" ")
  • if (tmplgt(MIDL200)) // if X-axis value gt
    setpoint plus 200
  • deltal (tmpl - (MIDL200))/200 // calculate
    the error and normalize it
  • diffl deltal-lastl // caculate the
    different between current and last error
  • if(difflltmaxdiff) // ignore if the error
    different gt max. difference
  • // this prevent the noise due to
    undesired movement of accelerometer
  • lastl deltal // save error as the last
    error
  • leftPWM leftPWM - (Pdeltal - Iaccul
    Ddiffl) // update the left PWM value by PID
  • if (leftPWMltMINOUTPUT) leftPWM MINOUTPUT //
    limit the PWM value to its minimum
  • if(acculltmaxaccu) accul deltal/200 //
    ensure the integral not exceed the maximum
  • PWMMR2leftPWM // set the left PWM output
  • PWMLER 0x24 //enable match 2,5 latch to
    effective
  • else if (tmpllt(MIDL-200)) // if X-axis
    value lt setpoint plus 200

30
if (tmplgt(MIDL200))Tile position gt ? degrees
(outside dead band)
  • void __irq IRQ_Exception() //running at 500Hz,
    set by timer
  • tmpl read_sensor(0) // read X-axis value
    //putint(tmpl)
  • if (tmplgt(MIDL200)) // if X-axis value gt
    setpoint plus 200
  • deltal (tmpl - (MIDL200))/200 //
    cal.error and normalize it
  • diffl deltal-lastl // cal. different
    between current and last error
  • if(difflltmaxdiff) // ignore if the error
    different gt max. difference
  • //prevents noise from undesired
    accelerometer movement lastl deltal // save
    error as the last error
  • leftPWM leftPWM - (Pdeltal - Iaccul
    Ddiffl)//updatePWM
  • if (leftPWMltMINOUTPUT)
  • leftPWM MINOUTPUT// limit PWM to
    its min.
  • if(acculltmaxaccu) //make sure accul
    cannot grow too big
  • accul deltal/200
  • // ensure integrallt maximum
  • PWMMR2leftPWM// set the left PWM output
  • PWMLER 0x24//enable match 2,5 latch to
    effective

31
Else of if (tmplgt(MIDL200))Tile position lt ?
degrees (outside dead band)
  • else if (tmpllt(MIDL-200))
  • Similar but the rotation is reversed
  • /////////////////////////////////////////////////
    ///

32
Question
  1. Is the output voltage changes linearly with the
    tilt angle?
  2. What is the effect on the performance of the
    system when the sampling frequency is 100Hz?
  3. The deadband in sensor reading is /-200.
    Estimate the deadband in degrees of our system.
  4. What is the effect on the performance of the
    system when the sampling frequency is 1000Hz?
    Explain your observation.

33
Conclusion
  • Studied how to interface direct currents sensor
    to a embedded system
  • Studied how to build and tune a PID control system
Write a Comment
User Comments (0)
About PowerShow.com