You are on page 1of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

%Lab 1
%Steve Brettschneider
%Sorin Mihaltan
%Rob Werk
%Fall '10
% Problem 1 ...............................
x=-20:.01:20;

%create domain

A=14+5*x+x.^2;
subplot(1,2,1);
plot(x,A); grid on;
title('Numerator');
xlabel('Input');
ylabel('Output');

%numerator

B=4-2*x+.5*x.^2;
subplot(1,2,2);
plot(x,B); grid on;
title('Denominator');
xlabel('Input');

%denominator

clf
funct=4*sqrt(A./B);
%entire function
plot(x,funct, 'b'); grid on;
title('Entire Function');
xlabel('Input');
ylabel('Output');

% Find Maximum
[max_funct,ind_max]=max(funct);
%find the max and obtain value and index
% Y Value
max_funct;
%y value
% X Value
x(ind_max);

%x value based on index

clf
% % Problem #2........................................
t=[0:.01:20]';
y1=1.5*exp(-t);
y2=3*exp(-.5*t);
y3=y2.*cos(.554*t+pi/4)+y1;
clf
y=[y1,y2,y3];

1 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

plot(t,y);
grid on;
xlabel('time in seconds');
ylabel('amplitude');
legend('y1','y2','y3');
title('Problem 2');
v=[0, 20, -1, 5];
axis(v);
% Determine y3(t) at t=2, t=6
indy3_2=find(t==2);
display('value at t=2');
y3(indy3_2)
indy3_6=find(t==6);
display('value at t=6');
y3(indy3_6)
% Determine minimum value of y3
[miny3, minind]=min(y3);
display('t value at minimum');
t(minind)
display('y3 value at minimum');
miny3
clf
% Problem 3........................................
% a)
t=[0:.01:20]';
x=fun1(t);
plot(t,x);
grid on;
xlabel('Input');
ylabel('Output');
title('Problem 3');
%b)
[maxX, maxind]=max(x);
display('value of t at maximum');
t(maxind)
display('value of x(t) at maximum');
maxX
%c)
area1=quad(@fun1,0,50)
display('the value of t0 is approximately');
for r=0:.01:10,
v = quad(@fun1,0,r);

2 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

if ((v > 32.3199) && (v<32.325))


t0=r;
end
end
t0
area2=quad(@fun1,0,t0);
%d)
plot(t,energyx);
grid on;
xlabel('Input');
ylabel('Output');
title('Problem 3');
enegy=quad(@energyx,0,50)

%Problem 4...........................
%a)
n1 = [-12:10];
n2 = [300:350];
n3 = [-12:8];
n4 = [-10:20];
n5 = [-12:12];
x1 = zeros(size(n1));
indx1_4 = find(n1==4);
x1(indx1_4) = 1;
subplot(5,1,1)
stem(n1,x1)
title('delta(n-4)')
%b)
x2 = zeros(size(n2));
indx2_320 = find(n2==320);
x2(indx2_320) = 2;
subplot(5,1,2)
stem(n2,x2)
title('2*delta(n-320)')
%c)
x3 = zeros(size(n3));
indx3_6 = find(n3==6);
indx3_m4 = find(n3==-4);
x3(indx3_6) = 3.6;
x3(indx3_m4) = 2.4;

3 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

subplot(5,1,3)
stem(n3,x3)
title('3.6*delta(n-6)+2.4*delta(n+4)')
%d)
x4 = zeros(size(n4));
indx4_m5to0 = find(n4<=0 & n4>=-5);
x4(indx4_m5to0) = 1;
subplot(5,1,4)
stem(n4,x4)
title('u(-n)*u(n+5)')
%e)
x5a = zeros(size(n5));
x5b = zeros(size(n5));
indx5a = find(n5<=2 & n5>=0);
indx5b = find(n5<=5 & n5>=0);
x5a(indx5a) = 1;
x5b(indx5b) = 1;
x5c = conv(x5a,x5b);
n5a = [-20:20];
x5 = x5c(12:36);
n5a>=-12 & n5a<=12
size(n5)
size(x5)
subplot(5,1,5)
stem(n5,x5)
xlabel('Time Index')
title('p3(n)*p6(n)')

%Problem 5..................................
n = 1:20;
n2 = 1:40;
%a)
x1 = cos(pi/7*n+pi/3);
subplot(4,2,1)
stem(n,x1)
xlabel('time index')
title('cos(pi/7*n+pi/3)')
w1 = pi/7;
w1/(2*pi);

4 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

p1 = 14;;
pavg1 = (x1(1:p1)*x1(1:p1)')/p1
%b)
x2 = sin(pi/15*n2+pi/4);
subplot(4,2,2)
stem(n2,x2)
xlabel('time index')
title('sin(pi/15*n+pi/4')
w2 = pi/15;
w2/(2*pi);
p2 = 30;
pavg2 = (x2(1:p2)*x2(1:p2)')/p2
%c)
x3 = sin(pi*n - pi/4);
subplot(4,2,3)
stem(n,x3)
xlabel('time index')
title('sin(pi*n-pi/2)')
w3 = 3*pi;
w3/(2*pi);
p3 = 2;
pavg3 = (x3(1:p3)*x3(1:p3)')/p3
%d)
x4 = cos(pi/sqrt(13)*n-pi/2);
subplot(4,2,4)
stem(n,x4)
xlabel('time index')
title('cos(pi/sqrt(13)*n)')
w4 = pi/sqrt(13);
w4/(2*pi);
%e)
x5 = cos(pi/4*n2)-3*cos(pi/3*n2-pi/3);
subplot(4,2,5)
stem(n2,x5)
xlabel('time index')
title('cos(pi/4*n)-3*cos(pi/3*n-pi/3)')
w5a = pi/4;
w5a/(2*pi);
w5b = pi/3;
w5b/(2*pi);

5 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

w5a/w5b;
p5 = 24;
pavg5 = (x5(1:p5)*x5(1:p5)')/p5
%f)
x6 = 4*cos(pi/5*n2+pi/4).*cos(pi/3*n2);
subplot(4,2,6)
stem(n2,x6)
xlabel('time index')
title('4*cos(pi/5*n+pi/4)*cos(pi/3*n)')
w6 = pi/7;
w6/(2*pi);
p6 = 15
pavg6 = (x6(1:15)*x6(1:15)')/p6
%g)
x7 = (2*sin(pi/10*n2))./(pi/10*n2);
subplot(4,2,7)
stem(n2,x7)
xlabel('time index')
title('2*sinc(pi/10*n)')
w7 = pi/7;
w7/(2*pi);

%Problem 6.............................
f = 600; % in Hz
fsamp = 8000; %in Hz
samp_T = 1/fsamp;
theta = -pi/4; % initial phase
t = [0:samp_T:.015]'; % Time in seconds
amp = 5;
x = amp * sin(2*pi*f*t+theta);
anlg_T = 1/f;
subplot(2,1,1);
plot(t,x,'r');
xlabel('Time Index (Seconds)');
ylabel('Amplitude');
grid on;
title('Signal as a function of Time in msec');
hold on
n=t/samp_T;
wo= 2*pi*f/fsamp; % digital frequency in rad/sample.
x1 = amp * sin(wo*n + theta);
hold off

6 of 7

9/27/10 8:41 AM

C:\Users\Sorin\Documents\Classes\ECE 480\Lab 1\lab1.m

subplot(2,1,2);
stem(n,x1,'g');
xlabel('Sample Index (n)');
ylabel('Amplitude');
grid on;
title('Signal as a function of the sample index');
digital_freq = 0.471238898038469; % radians

% Problem 7......................................
%Part a plot x(n) from n=[0,10]
n=[0:10];
x = 2*(-0.8).^n;
stem(n,x);
v = [0,10, -2,2];
axis(v); grid on

%Part b Find the sum and check using the close form
summed_ans = sum(x);% finds the summation from [0,10]
L=max(n)+1;
Sumation=2*((1-(-0.8)^L)/(1-(-0.8)));

% Part c Find the sum for all intergers


n_infinity=[0:9000000]'; %Not quite infinity but close.
x1=2*(-0.8).^n_infinity;
summed_ans2 = sum(x1);
%Part d find the energy of x(n)
eng_x = sum(abs(x1.^2));

7 of 7

You might also like