Download presentation
Presentation is loading. Please wait.
Published byChloe Boyd Modified over 9 years ago
1
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
2
206_M62 Dot Product Scalar formed by sum of products of vector elements dot_product = sum(A.*B); dot_product = A_row * B_col; dot(A,B);
3
206_M63 Example Find Total Mass num_items = [ 3 5 2 1 ] mass_items = [3.5 1.5.79 1.75] item_totals = num_items.* mass_items total_mass = sum(item_totals) total_mass = num_items * mass_items’ total_mass = dot(num_items,mass_items)
4
206_M64 Matrix Multiplication Value in position (i,j) is dot product of row i of the first matrix with column j of the second matrix Inner dimensions must be the same (conformable) A = [2 5 1;0 3 -1] (2 x 3) B = [1 0; -1 4; 5 2] (3 x 2) C = A * B (2 x 2) C11 = sum(A(1,:).*B(:,1)')
5
206_M65 Matrix Powers Square of each element of a matrix A.^2 Square of a matrix A^2 A*A Other powers A^3 A*A*A...
6
206_M66 Other Matrix Functions Matrix Inverse Product of matrix and it's inverse yields identity matrix AA -1 = I and A -1 A = I B = inv(A) I = A*B Determinant Scalar computed from entries of a square matrix e.g. (2 x 2): |A| = a 1,1 a 2,2 - a 2,1 a 1,2 det(A)
7
206_M67 Special Matrices Matrix of Zeros zeros(3) zeros(3,2) Matrix of Ones ones(3) ones(3,2) Identity Matrix eye(3)
8
206_M68 Systems of Linear Equations System of 3 equations with 3 unknowns 3x 1 + 2x 2 - x 3 = 10 -x 1 + 3x 2 + 2x 3 = 5 x 1 - x 2 - x 3 = -1 Matrix representation AX = B
9
206_M69 Solving Simultaneous Equations Solution Using the Matrix Inverse AX = B A -1 AX = A -1 B IX = A -1 B X = A -1 B MATLAB Solution X = inv(A)*B Better MATLAB Solution using Left Division X = A\B Uses Gaussian elimination (without forming the inverse)
10
206_M610 Signal-to-Noise Ratio Signal Power (Amplitude) power = sum(x.^2)/length(x) Signal Power (Variance and Mean) power = std(x)^2 + mean(x)^2 Signal Power (Sinusoid) x = A*sin(2*pi*t) power = A^2/2 Signal-to-Noise Ratio SNR = (signal power)/(noise power)
11
206_M611 Random Numbers Uniform Random Numbers rand('seed',n), rand(n), rand(m,n) Interval 0 to 1 Interval a to b x = (b - a)*r + a; Gaussian Random numbers randn('seed',n), randn(n), randn(m,n) Normal Distribution Mean = 0, Standard Deviation = 1.0 Modified Distribution Mean = b, Standard Deviation = a x = a*r + b;
12
206_M612 Random Noise Uniform Noise rand(1,n) Interval -a to +a mean = 0 variance = a 2 /3 x = 2*a*r - a Gaussian Noise randn(1,n) Standard Deviation = a mean = 0 variance = a 2 x = a*r
13
206_M613 Sinusoid plus Uniform Noise % Sine plus Uniform Noise t=0:0.01:2; sine=4*sin(2*pi*t); noise_u=2*rand(1,201)-1; s_u=sine+noise_u; power_sine=sum(sine.^2)/length(sine) power_noise_u=sum(noise_u.^2)/length(noise_u) SNR_u=power_sine/power_noise_u figure(1) plot(t,s_u) figure(2) hist(noise_u)
14
206_M614 Sinusoid plus Gaussian Noise % Sine plus Gaussian Noise t=0:0.01:2; sine=4*sin(2*pi*t); noise_g=1/sqrt(3)*randn(1,201); s_g=sine+noise_g; power_sine=sum(sine.^2)/length(sine) power_noise_g=sum(noise_g.^2)/length(noise_g) SNR_g=power_sine/power_noise_g figure(3) plot(t,s_g) figure(4) hist(noise_g)
15
206_M615 Problem Solving Applied Signal Generation with Noise Problem Statement Generate a sinusoidal signal with a given amplitude and addition of uniform noise with a specified signal- to-noise ratio Input/Output Description Signal Plot Signal and Noise Power SNR Sine Wave Amplitude Desired SNR
16
206_M616 Problem Solving Applied Hand Example SNR = (signal power)/(noise power) signal power = A 2 /2 noise power = a 2 /3 Algorithm Development Prompt for A and SNR Compute a Generate sine and noise Compute powers and SNR Plot sine plus noise
17
206_M617 MATLAB Solution % Sine plus Uniform Noise at SNR A = input('Enter amplitude of sinusoid: '); SNR = input('Enter desired signal-to-noise ratio: '); a=sqrt(1.5*A^2/SNR); t=0:0.01:2; sine=A*sin(2*pi*t); noise_u=2*a*rand(1,201)-a; power_sine=sum(sine.^2)/length(sine); power_noise_u=sum(noise_u.^2)/length(noise_u); SNR_u=power_sine/power_noise_u s_u=sine+noise_u; plot(t,s_u) title('Sinusoid with Uniform Noise')
18
206_M618 Summary Matrix Computations Systems of Simultaneous Equations Signal-to-Noise Ratio
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.