Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab descriptions Lab: Pitch tuner Lab: Self balancing platform Labs: pitch tuner and self balancing platform (v.5b) 1.

Similar presentations


Presentation on theme: "Lab descriptions Lab: Pitch tuner Lab: Self balancing platform Labs: pitch tuner and self balancing platform (v.5b) 1."— Presentation transcript:

1 Lab descriptions Lab: Pitch tuner Lab: Self balancing platform Labs: pitch tuner and self balancing platform (v.5b) 1

2 2 Laboratory 1 A simple Pitch tuner

3 Labs: pitch tuner and self balancing platform (v.5b) 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 Labs: pitch tuner and self balancing platform (v.5b) 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 Labs: pitch tuner and self balancing platform (v.5b) 5 Hardware system ADC input ARM7 PC for display result RS232 Mic amp

6 Labs: pitch tuner and self balancing platform (v.5b) 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: Input=1KHZ, find impedance of C1 and input of the amp. –Solution: C1>1uF, R2=1K, V3 = 100K(VR), use, one VR to replace VR1,2. Discuss why?

7 Labs: pitch tuner and self balancing platform (v.5b) 7 Software: Algorithm to find period=1/frequency Digitize signal Find auto correlation coefficients r() : r0,r1,…,rn Period= distance between two peaks of r()

8 Pitch Estimation Method : ACF (Autocorrelation function) Autocorrelation function (ACF) Labs: pitch tuner and self balancing platform (v.5b) 8 Symmetrical on both side R x n n m

9 What is Auto- correlation, R(m)? E.g. x=[1 5 7 1 4 ] N=5, R(0)=[x(0)*x(0)+x(1)*x(1)+x(2)*x2+x(3)*x(3)+x(4)*x(4)] R(0)= (1+ 25+49+1+16)=92 R(1)=[x(0)*x(1)+x(1)*x(2)+x(2)*x(3)+x(3)*x(4)] x=[1 5 7 1 4 ] [1 5 7 1 4 ] (5+ 35+ 7+ 4)=51 And so on… R=[ 92.0000 51.0000 40.0000 21.0000 4.0000 ] Labs: pitch tuner and self balancing platform (v.5b) 9

10 Example. First, what is auto- correlation? %matlab code fs=1 x=[1 5 7 1 4 8 6 2 4 9 3 ]' auto_corr_x=xcorr(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_ind]=max(pks) 'peak value1 at location' pks(peak1_ind) %peak locs (peak1_ind) %location 'peak value2 at location' pks(peak1_ind+1)%peask next to the top peak locs (peak1_ind+1) %location period=locs(peak1_ind+1)-locs(peak1_ind) pitch_Hz=fs/period %display pitch in Hz %peaks at t=11,15, dt=15-11=4 Exercise: Show the steps of calculation Labs: pitch tuner and self balancing platform (v.5b) 10 X[t] Auto_correlation(x[t]) t We only look at positive n Gap between two peaks is 4, so period of X is around 4 Ans: ?? R(m)

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. Labs: pitch tuner and self balancing platform (v.5b) 11 Lag Time j in samples Auto correlation R(j) R the_max (j 1 ) R second_max (j 2 ) j 1 =0j2j2 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: Usually assume j 1 =0, then Labs: pitch tuner and self balancing platform (v.5b) 12

13 Testing a real sound A5_flute 880Hz, (sampling at fs=44100Hz) %testing a real sound, matlab code %x=[1 3 7 2 1 9 3 1 8 ], [xx,fs,nbits]=wavread('c:\sounds\A5_flute.wav'); sound(x,fs)%fs=44100Hz, fs %sampling freuqncy start=10000; %pitch a fram around t=10000 length=512; x=xx(start:start+length); auto_corr_x=xcorr(x); %auto-correlation figure(1), clf subplot(2,1,1),plot(x) title(' one frame of the sound A5-flute=880Hz') 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_ind]=max(pks) 'peak value1 at location' pks(peak1_ind) %peak locs (peak1_ind) %location 'peak value2 at location' pks(peak1_ind+1)%peask next to the top peak locs (peak1_ind+1) %location period=locs(peak1_ind+1)-locs(peak1_ind) pitch_Hz=fs/period %display pitch in Hz Labs: pitch tuner and self balancing platform (v.5b) 13 Use sort( ) in matlab to find the two peaks, The gap between 2 peaks is dt=563-513=50, hence frequency is fs/dt=44100/50=882 Hz. Note: Pitch of a flute sound played by a human may not be too stable. 2 peaks at t=513, 563 Auto_correlation(x[t]) (x[t])

14 Labs: pitch tuner and self balancing platform (v.5b) 14 Matlab example 1 a=[1 3 9 3 2 3 8 3 2 ], r=(xcorr(a)),round (r) R=r(j=time 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 Labs: pitch tuner and self balancing platform (v.5b) 15 Matlab Example2: a=[1 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) Period=4, Auto Corr. Xcorr (r) Data (a) Pick 2 peaks and measure period The middle is the peak

16 Labs: pitch tuner and self balancing platform (v.5b) 16 Since correlation is mirrored at the lag time (j=0) when the signal overlapped with itself Only positive time lag is considered Fundamental Period=j 2 Lag Time j in samples Auto correlation R(j) R the_max (j 1 ) R second_max (j 2 ) j 1 =0 j2j2

17 Labs: pitch tuner and self balancing platform (v.5b) 17 Matlab Example3: y=sin wave of 440 Hz dt=0.0001 time=[0:dt:2] freq=440 nu=2.0*pi*freq y=sin(nu*time) %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(1:100),r(1:100))

18 Labs: pitch tuner and self balancing platform (v.5b) 18 Matlab Example3: In fact any two peaks will give you the answer sine wave of 440 Hz, period=0.0091-0.0068 (by inspection between 2 peaks) freq=1/period=434.7Hz input Data (y) Auto Corr. (r) 0.0068 0.0091

19 Labs: pitch tuner and self balancing platform (v.5b) 19 Conclusion Studied a method of measuring the pitch of an audio sound.

20 Labs: pitch tuner and self balancing platform (v.5b) 20 Laboratory 2 A self balancing platform

21 Labs: pitch tuner and self balancing platform (v.5b) 21 Objectives 1. Objectives –To lean how to interface a direct current (DC) output sensor to an microcontroller –To learn how to implement a Proportional–Integral– Derivative PID feed back control system.Proportional–Integral– Derivative PID 2. Aim –To develop a self-balancing platform using an embedded system. Reference: http://www.cse.cuhk.edu.hk/%7Ekhwong/ceg3480/PID_DC_motor_Control08.ppt

22 Labs: pitch tuner and self balancing platform (v.5b) 22 PWM generator control method: PID (proportional-integral-derivative) control Required position=0 Left_pwm + - tmpl Integral control I* (deltal) dt Proportional control =P*(deltal) Derivative control D*d(deltal)/dt ; sum error term e=0-tmpl =deltal Position Sensor (tmpl) 0

23 Labs: pitch tuner and self balancing platform (v.5b) 23 The experimental setup video

24 Labs: pitch tuner and self balancing platform (v.5b) 24 Fig. 1b.Block Diagram of the Self- balancing platform

25 Labs: pitch tuner and self balancing platform (v.5b) 25 Fig. 2 Two channels DC amplifier circuit

26 Labs: pitch tuner and self balancing platform (v.5b) 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 Labs: pitch tuner and self balancing platform (v.5b) 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. x=200 in our example) –tmpl is the tilt position measurement e=deltal = (tmpl - (MIDL+200)) / 200; Derivative is d[e(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 Labs: pitch tuner and self balancing platform (v.5b) 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-bandsignalrange Dead-band

29 Labs: pitch tuner and self balancing platform (v.5b) 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 (tmpl>=(MIDL+200)) {// if X-axis value >= setpoint plus 200 deltal = (tmpl - (MIDL+200))/200;// calculate the error and normalize it diffl = deltal-lastl;// caculate the different between current and last error if(diffl max. difference // this prevent the noise due to undesired movement of accelerometer lastl = deltal;// save error as the last error leftPWM = leftPWM - (P*deltal - I*accul + D*diffl);// update the left PWM value by PID if (leftPWM<MINOUTPUT) leftPWM = MINOUTPUT;// limit the PWM value to its minimum if(accul<maxaccu) accul += deltal/200;// ensure the integral not exceed the maximum PWMMR2=leftPWM;// set the left PWM output PWMLER = 0x24;//enable match 2,5 latch to effective } else if (tmpl<=(MIDL-200)) {// if X-axis value <= setpoint plus 200 deltal = ((MIDL-200) - tmpl)/200;// calculate the error and normalize it diffl = deltal- lastl; // caculate the different between current and last error if(diffl max. difference // this prevent the noise due to undesired movement of accelerometer lastl = deltal; // save error to the last error leftPWM = leftPWM + P*deltal + I*accul + D*diffl; // update the left PWM value by PID if (leftPWM>MAXOUTPUT) leftPWM = MAXOUTPUT;// limit the PWM value to its maximum if(accul>0)accul -= deltal/100; // ensure the integral not less than zero PWMMR2=leftPWM; // set the left PWM output PWMLER = 0x24;//enable match 2,5 latch to effective } ////////////////////////////////////////////////////

30 Labs: pitch tuner and self balancing platform (v.5b) 30 if (tmpl>=(MIDL+200)) Tile position >  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 (tmpl>=(MIDL+200)) {// if X-axis value >= setpoint plus 200 deltal = (tmpl - (MIDL+200))/200; // cal.error and normalize it diffl = deltal-lastl;// cal. different between current and last error if(diffl max. difference {//prevents noise from undesired accelerometer movement lastl = deltal;// save error as the last error leftPWM = leftPWM - (P*deltal - I*accul +D*diffl);//updatePWM if (leftPWM<MINOUTPUT) leftPWM = MINOUTPUT;// limit PWM to its min. if(accul<maxaccu) //make sure accul cannot grow too big accul += deltal/200; // ensure integral< maximum PWMMR2=leftPWM;// set the left PWM output PWMLER = 0x24;//enable match 2,5 latch to effective }

31 Labs: pitch tuner and self balancing platform (v.5b) 31 Else of if (tmpl>=(MIDL+200)) Tile position <=  degrees (outside dead band) else if (tmpl<=(MIDL-200)) { Similar but the rotation is reversed }////////////////////////////////////////////////////

32 Labs: pitch tuner and self balancing platform (v.5b) 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 Labs: pitch tuner and self balancing platform (v.5b) 33 Conclusion Studied how to interface direct currents sensor to a embedded system Studied how to build and tune a PID control system


Download ppt "Lab descriptions Lab: Pitch tuner Lab: Self balancing platform Labs: pitch tuner and self balancing platform (v.5b) 1."

Similar presentations


Ads by Google