Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Gonzaga Jan Russel P.

ECE107L-E02

1. Generate the following signals and plot each one with respect to time.
a. 128 samples of sinusoid with frequency of 1000 Hz, amplitude of 0.8 and sampling rate of
8000Hz.
Syntax:
>> fs1=8000
fs =
8000
>> t=[0:127]/fs1;
>> y=0.8*sin(2*pi*2000*t);
>> plot(t, y,'c>:')

b. Repeat 1a with sampling frequency of 6000Hz, 4050Hz, and 3900Hz.


Is there a change in output waveform?
Syntax:
>> fs1=8000;
>> fs2=6000;
>> fs3=4050;
>> fs4=3900;
>> fs1t=[0:127]/fs;
>> fs1t=[0:127]/fs1;
>> fs2t=[0:127]/fs2;
>> fs3t=[0:127]/fs3;
>> fs4t=[0:127]/fs4;
>> fs1y=0.8*sin(2*pi*2000*fs1t);
>> fs2y=0.8*sin(2*pi*2000*fs2t);
>> fs3y=0.8*sin(2*pi*2000*fs3t);
>> fs4y=0.8*sin(2*pi*2000*fs4t);
>> subplot(4,1,1),plot(fs1t,fs1y,'c>: '),
subplot(4,1,2),plot(fs2t,fs2y,'c>:'),
subplot(4,1,3),plot(fs3t,fs3y,'c>:'),
subplot(4,1,4),plot(fs4t,fs4y, 'c>:')
c. 250ms of an exponentially decaying signal with a time constant of 50ms; and sampling rate
is 1000Hz.
Syntax:
fs=1000;
t=[0:(1/fs):0.249];
>> y=exp(-t/0.05);
>> plot(t,y,'c>:')

d. Compare the length of the signals in 1a and 1c. perform zero-padding at the end of the
signal with shorter length such that the two signals will have the same length. Multiply the
two signals. Plot and describe the resulting waveform.
Syntax:
>> fs=8000;
>> t=[0:127]/fs;
>> y=0.8*sin(2*pi*2000*t);
>> length(y)
ans =
128
fs1=1000;
>> t1=[0:(1/fs1):0.249];
>> y1=exp(-t1/0.05);
>> length(y1)
ans =
250
>> y2=[y zeros(1,122)];
>> yt=y1.*y2;

>> plot(t1,yt,'c>:')
2. a. Create and plot a sine having fundamental frequency of 75hz with 300 samples, amplitude of
2 and sampling rate of 8000hz
Sytanx:
>> fs=8000;
>> t=[0:299]/fs;
>> y=2*sin(2*pi*75*t)
>> plot(y,'c>:')

b. Add 10 harmonics to the fundamental, with amplitudes of 1/k where k=harmonic number.
Plot and describe the resulting waveform.
Syntax:
>> fs=8000;
>> t=[0:299]/fs;
>> k=1;y1=(1/k)*2*sin(2*pi*75*k*t);
>> k=2;y2=(1/k)*2*sin(2*pi*75*k*t);
>> k=3;y3=(1/k)*2*sin(2*pi*75*k*t);
>> k=4;y4=(1/k)*2*sin(2*pi*75*k*t);
>> k=5;y5=(1/k)*2*sin(2*pi*75*k*t);
>> k=6;y6=(1/k)*2*sin(2*pi*75*k*t);
>> k=7;y7=(1/k)*2*sin(2*pi*75*k*t);
>> k=8;y8=(1/k)*2*sin(2*pi*75*k*t);
>> k=9;y9=(1/k)*2*sin(2*pi*75*k*t);
>> k=10;y10=(1/k)*2*sin(2*pi*75*k*t);
>> k=11;y11=(1/k)*2*sin(2*pi*75*k*t);
>> ysum=y1+y2+y3+y4+y5+y6+y7+y8
+y9+y10+y11;
>> plot(ysum,'c>:')
c. Add 10 harmonics to the fundamental, with the amplitudes of 1/k where k= number of
harmonics. Plot and describe the resulting waveform.
Syntax:
>> fs=8000;
>> t=[0:299]/fs;
>> k=1;y1=(1/k)*2*sin(2*pi*75*k*t);
>> k=3;y3=(1/k)*2*sin(2*pi*75*k*t);
>> k=5;y5=(1/k)*2*sin(2*pi*75*k*t);
>> k=7;y7=(1/k)*2*sin(2*pi*75*k*t);
>> k=9;y9=(1/k)*2*sin(2*pi*75*k*t);
>> k=11;y11=(1/k)*2*sin(2*pi*75*k*t);
>> k=13;y13=(1/k)*2*sin(2*pi*75*k*t);
>> k=15;y15=(1/k)*2*sin(2*pi*75*k*t);
>> k=17;y17=(1/k)*2*sin(2*pi*75*k*t);
>> k=19;y19=(1/k)*2*sin(2*pi*75*k*t);
>> k=21;y21=(1/k)*2*sin(2*pi*75*k*t);
>> ysum=y1+y3+y5+y7+y9+y11
+y13+y15+y17+y19+y21;
>> plot(ysum,'c>:')

d. Add 10 harmonics to the fundamental with amplitudes of (-1)^m/k^2 where l = harmonic


number and m=((k-1)/2)^2. Plot and describe the resulting waveform.
Syntax:
>> fs=8000;
>> t=[0:299]/fs;
>> k=1;m=((k-1)/2)^2;y1=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=3;m=((k-1)/2)^2;y3=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=5;m=((k-1)/2)^2;y5=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=7;m=((k-1)/2)^2;y7=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=9;m=((k-1)/2)^2;y9=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=11;m=((k-1)/2)^2;y11=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=13;m=((k-1)/2)^2;y13=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=15;m=((k-1)/2)^2;y15=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=17;m=((k-1)/2)^2;y17=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=19;m=((k-1)/2)^2;y19=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> k=21;m=((k-1)/2)^2;y21=(((-1)^m)/(k^2))*2*sin(2*pi*75*k*t);
>> ysum=y1+y3+y5+y7+y9+y11+y13+y15+y17+y19+y21;
>> plot(t,ysum,'c>:')
3. Plot the following 3-D figures below. Save display on your respected group folder. Let your
instructor check result of 3D plotting for verification.

a. Generate the x and y coordinates using meshgrid with range from -3pi to 3pi and increment of
0.1. solve sine(R) with R=sqrt(x.^2+y.^2). Display 3D graph of sine function using plot3 command.

Syntax:

[x,y]=meshgrid((-3*pi):0.1:(3*pi));

>> R=sqrt((x.^2)+(y.^2));

>> z=(sin(R))./R;

>> plot3(x,y,z)

Description:

The figure looks like the

phenomenon when a water droplet

falls into a liquid surface.


b. using same sinc(R) result in 3a plot 3D graph using contour3 command with 30 counter levels.

Syntax:

[x,y]=meshgrid((-3*pi):0.1:(3*pi));

>> R=sqrt((x.^2)+(y.^2));

>> z=(sin(R))./R;

>> contour3(x,y,z,30)

Description:

The figure looks like an upside down tornado.

c. geberate polar coordinate (z) of complex grid using the command cplxgrid with 30 grids.
Display the complex function using cplxmap command.

i.) f(z)=(z.^5).^(1/8)

Syntax:

>> contour3(x,y,z,30)

>> z=cplxgrid(30);

>> a=(z.^5).^(1/8);

>> cplxmap(z,a)

Description:

The figure partly looks like a lily flower.


Ii)f(z)=tan^-1(2*z)

Syntax:

z=cplxgrid(30);

>> c=atan(2*z);

>> cplxmap(z,c);

Description:

The figure looks like a waterfall.

You might also like