-4 -3 -2 -1 0 1 2 3 4 - me 363 elementary...

23

Upload: others

Post on 31-Jan-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 2: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 3: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

-4 -3 -2 -1 0 1 2 3 4-1.5

-1

-0.5

0

0.5

1

1.5

t (s)

y

Problem 2.16 from Figliola & Beasley, 4th Ed.

1st partial sum

2nd partial sum

3rd partial sum

Page 4: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 5: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 6: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

-5 -4 -3 -2 -1 0 1 2 3 4 5-5

-4

-3

-2

-1

0

1

2

3

4

5

t (s)

y

Problem 2.16 from Figliola & Beasley, 4th Ed.

1st partial sum

2nd partial sum

3rd partial sum

Page 7: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 8: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 9: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 10: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:20 PM C:\Documents and Setti...\dft_data1.m 1 of 2

% This m-file computes the DFT of fictitious sensor% data.%% Mark Colton% 3/3/2010 clear;clc; % Load dataload data1.dat;t = data1(:,1);y = data1(:,2);clear data1; % Plot datafigure(1);plot(t,y);ylabel('V_s_e_n_s_o_r (V)');xlabel('t (s)');title('Fictitious Sensor Data'); % Find important information about datadt = t(2)-t(1)fs = 1/dt%N = length(t)-1N = length(t) % Step through k = 0:N/2, to find a(k) and b(k).% The maximum frequency at which fourier coefficients% can be found is fmax = fs/2.for k = 0:N/2, % Initialize summations to zero ar = 0;

Page 11: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:20 PM C:\Documents and Setti...\dft_data1.m 2 of 2

br = 0; % Step through each time step and perform summations. for r = 1:N, ar = ar + y(r)*cos(2*pi*k*r/N); br = br + y(r)*sin(2*pi*k*r/N); end % At each frequency step, find the fourier coefficients. % Note that MATLAB can't use zero indices, so I bump % them up by one. a(k+1) = 2/N*ar; b(k+1) = 2/N*br; c(k+1) = sqrt(a(k+1)^2 + b(k+1)^2); % Also calculate the frequency corresponding to each % fourier coefficient. f(k+1) = k/N/dt;end % Plot fourier coefficients vs. frequencyfigure(2);plot(f,c);ylabel('c_k');xlabel('f (Hz)');title('DFT of Fictitious Sensor Data'); % Find non-zero fourier coefficients and associated% frequenciesk = find(c > 0.1);fk = f(k)ck = c(k)ak = a(k)bk = b(k)

Page 12: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

Vse

nsor

(V

)

t (s)

Fictitious Sensor Data

Page 13: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

0 50 100 150 200 2500

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

c k

f (Hz)

DFT of Fictitious Sensor Data

Page 14: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:26 PM MATLAB Command Window 1 of 2

dt = 0.0020 fs = 500 N = 2500 fk = 1 15 27 42 ck = 1.0000 0.6200 0.3400 0.2200 ak = -0.0126 -0.1162 -0.1132 -0.1108 bk = 0.9999 0.6090 0.3206 0.1901

Page 15: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:24 PM C:\Documents and Setting...\dft_emg.m 1 of 2

% This m-file computes the DFT of experimental EMG% data.%% Mark Colton% 3/3/2010 clear;clc; % Load EMG dataload emg_data.dat;t = emg_data(:,1);y = emg_data(:,2);clear emg_data; % Plot EMG datafigure(1);plot(t,y);ylabel('V_e_m_g (V)');xlabel('t (s)');title('EMG Data'); % Find important information about datadt = t(2)-t(1)fs = 1/dtN = length(t)-1 % Step through k = 0:N/2, to find a(k) and b(k).% The maximum frequency at which fourier coefficients% can be found is fmax = fs/2.for k = 0:N/2, % Initialize summations to zero ar = 0; br = 0;

Page 16: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:24 PM C:\Documents and Setting...\dft_emg.m 2 of 2

% Step through each time step and perform summations. for r = 1:N, ar = ar + y(r)*cos(2*pi*k*r/N); br = br + y(r)*sin(2*pi*k*r/N); end % At each frequency step, find the fourier coefficients. % Note that MATLAB can't use zero indices, so I bump % them up by one. a(k+1) = 2/N*ar; b(k+1) = 2/N*br; c(k+1) = sqrt(a(k+1)^2 + b(k+1)^2); % Also calculate the frequency corresponding to each % fourier coefficient. f(k+1) = k/N/dt;end % Plot fourier coefficients vs. frequencyfigure(2);plot(f,c);ylabel('c_k');xlabel('f (Hz)');title('DFT of EMG Data');

Page 17: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6-3

-2

-1

0

1

2

3

4

5

6x 10

-4

Vem

g (V

)

t (s)

EMG Data

Page 18: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

0 100 200 300 400 500 600 700 8000

1

2

3

4

5

6x 10

-6

c k

f (Hz)

DFT of EMG Data

Page 19: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4
Page 20: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:36 PM C:\Documents and Se...\filter_data1.m 1 of 3

% This m-file illustrates the use of a filter on fictitious% sensor data.%% Mark Colton% 3/3/2010 clear;clc; % Load dataload data1.dat;t = data1(:,1);y = data1(:,2);clear data1; % Find important information about datadt = t(2)-t(1);fs = 1/dt;N = length(t); % Step through k = 0:N/2, to find a(k) and b(k).% The maximum frequency at which fourier coefficients% can be found is fmax = fs/2.for k = 0:N/2, % Initialize summations to zero ar = 0; br = 0; % Step through each time step and perform summations. for r = 1:N, ar = ar + y(r)*cos(2*pi*k*r/N); br = br + y(r)*sin(2*pi*k*r/N); end

Page 21: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:36 PM C:\Documents and Se...\filter_data1.m 2 of 3

% At each frequency step, find the fourier coefficients. % Note that MATLAB can't use zero indices, so I bump % them up by one. a(k+1) = 2/N*ar; b(k+1) = 2/N*br; c(k+1) = sqrt(a(k+1)^2 + b(k+1)^2); % Also calculate the frequency corresponding to each % fourier coefficient. f(k+1) = k/N/dt;end % Find non-zero fourier coefficients and associated% frequenciesk = find(c > 0.1);fk = f(k);ck = c(k);ak = a(k);bk = b(k); % Filtertau = 0.1;K = 1; % Use fourier coefficients to reconstruct signalyf = zeros(size(t)); for k = 1:length(fk), % Filtered signal M(k) = 1/sqrt(1 + (2*pi*fk(k)*tau)^2); phi(k) = -atan(2*pi*fk(k)*tau); yf = yf + M(k)*K*ak(k)*cos(2*pi*fk(k)*t+phi(k)) + M(k)*K*bk(k)*sin(2*pi*fk(k)*t+phi(k));end

Page 22: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

3/3/10 3:36 PM C:\Documents and Se...\filter_data1.m 3 of 3

% Plot resultsfigure(1);plot(t,y,'k',t,yf,'r');ylabel('V_s_e_n_s_o_r (V)');xlabel('t (s)');title('Fictitious Sensor Data');legend('Raw','Filtered');

Page 23: -4 -3 -2 -1 0 1 2 3 4 - ME 363 Elementary Instrumentationme363.byu.edu/sites/me363.byu.edu/files/hw1_solutions.pdf · 2012-05-17 · -5 -4 -3 -2 -1 0 1 2 3 4 5-5-4-3-2-1 0 1 2 3 4

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

Vse

nsor

(V

)

t (s)

Fictitious Sensor Data

RawFiltered