Module 2
Module 2
Module 2
ECE107L/ A1 MODULE 2
1. Generate the following signals and plt each one with respect to time
a. 128 samples of sinusoid with frequency of 2000 Hz, amplitude of 0.5 and sampling rate
is 8000 Hz.
Syntax:
>> fs=8000;
>> t = [0:127]/fs;
>> y = 0.8*sin(2*pi*2000*t);
>> plot(t,y,'m-<');
>> plot(t,y,'m--<');
b. Repeat 1a with sampling frequency of 6000 Hz, 4050 Hz, and 3900 Hz.
Syntax:
>> plot(t,y,'m--<');
Is there a change in output waveforms? Explain.
The output from sampling rate of 6000Hz to 8000 Hz, the output looks like a normal sinusoidal wave.
The sampling rates from 3900Hz to 4050Hz looks like standing waves.
c. 250ms of an exponentially decaying signal with a time constant of 50ms; and sampling
rate is 1000Hz.
Syntax:
>> fs1=1000;
>> t1=[0:(1/fs1):0.249];
>> y1=exp(-t1/0.050);
>> plot(t1,y1,'m--<');
d. Compare the lengths 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:
The graph is the sum of the two signals. It resembles a tower rotated to the left.
Syntax:
>> fs = 8000;
>> t=[0:127]/fs;
>> y=0.8*sin(2*pi*2000*t);
>> length(y);
>> fs2=1000;
>> t1=[0:(1/fs2):0.249];
>> y1=exp(-t1/0.050);
>> length(y1);
>> y(1,250)=0;
>> y3=y.*y1;
>> plot(t1,y3,'m--<');
2. a. Create and plot a sine wave having fundamental frequency of 75Hz with 300 samples,
amplitude of 2, and sampling rate of 8000Hz.
Syntax:
>> fs = 8000;
>> t=[0:299]/fs;
>> y=2*sin(2*pi*75*t);
>> plot(t,y,'m--<');
b. Add 10 harmonics to the fundamental, with amplitudes of 1/k, where k = harmonic
number. Plot and describe the resulting waveform: The output waveform formed by the sum
of the harmonics looks like a sawtooth wave
Syntax:
>> fs = 8000;
>> t=[0:299]/fs;
>> y=2*sin(2*pi*75*t);
>> k=1;y1=(1/k);sin(2*pi*75*t*k);
>> k=2;y2=(1/k)*sin(2*pi*75*t*k);
>> k=3;y3=(1/k)*sin(2*pi*75*t*k);
>> k=4;y4=(1/k)*sin(2*pi*75*t*k);
>> k=5;y5=(1/k)*sin(2*pi*75*t*k);
>> k=6;y6=(1/k)*sin(2*pi*75*t*k);
>> k=7;y7=(1/k)*sin(2*pi*75*t*k);
>> k=8;y8=(1/k)*sin(2*pi*75*t*k);
>> k=9;y9=(1/k)*sin(2*pi*75*t*k);
>> k=10;y10=(1/k)*sin(2*pi*75*t*k);
>> k=11;y11=(1/k)*sin(2*pi*75*t*k);
>> yt=y1+y2+y3+y4+y5+y6+y7+y8+y9+y10+y11;
>> plot(t,yt,'m--<');
c. Add 10 odd harmonics to the fundamental, with amplitude of 1/k, where k = harmonic
number. Plot and describe the resulting waveform: The output waveform formed by the odd
harmonics looks like rectangular wave
Syntax:
>> fs = 8000;
>> t=[0:299]/fs;
>> k=1;y1=(1/k)*sin(2*pi*75*t*k);
>> k=3;y3=(1/k)*sin(2*pi*75*t*k);
>> k=5;y5=(1/k)*sin(2*pi*75*t*k);
>> k=7;y7=(1/k)*sin(2*pi*75*t*k);
>> k=9;y9=(1/k)*sin(2*pi*75*t*k);
>> k=11;y11=(1/k)*sin(2*pi*75*t*k);
>> k=13;y13=(1/k)*sin(2*pi*75*t*k);
>> k=15;y15=(1/k)*sin(2*pi*75*t*k);
>> k=17;y17=(1/k)*sin(2*pi*75*t*k);
>> k=19;y19=(1/k)*sin(2*pi*75*t*k);
>> k=21;y21=(1/k)*sin(2*pi*75*t*k);
>> yt=y1+y3+y5+y7+y9+y11+y13+y15+y17+y19+y21;
>> plot(t,yt,'m--<');
d. Add 10 odd harmonics to the fundamental, with amplitudes of (-1)^m /k^2 where k =
harmonic number and m=((k- 1)/2)^2. Plot and describe the resulting waveform.
The output looks like a triangular waveform.
Syntax:
>> fs = 8000;
>> t=[0:299]/fs;
>> k=1; y1=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=3; y3=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=5; y5=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=7; y7=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=9; y9=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=11; y11=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=13; y13=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=15; y15=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=17; y17=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=19; y19=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> k=21; y21=(2*((-1)^(((k-1)/2)^2)/(k^2))*sin(2*pi*75*k*t));
>> yt = y1+y3+y5+y7+y9+y11+y13+y15+y17+y19+y21;
>> plot(t,yt,'m--<');
3. Plot the following 3-D figures below. Save display on your respective 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 sinc® with R = sqrt(x.^2+y.^2). Display 3D graph of sinc function
using plot3. Hint: sinc(R) = sin(R)./R
Syntax:
>> [x,y]=meshgrid(-3*pi:0.1:3*pi);
>> R=sqrt(x.^2+y.^2);
>> Z=(sin(R))./R;
>> plot3(x,y,Z);
Describe the output waveform: The output waveform looks like a sombrero with wavy
edges and has a steep maxima point.
b. Using same sinc(R) result in 3a, plot 3D graph using contour3 command with 30 contour
levels.
Syntax:
>> [x,y]=meshgrid(-3*pi:0.1:3*pi);
>> R=sqrt(x.^2+y.^2);
>> Z=(sin(R))./R;
>> contour3(Z,30);
Describe the output waveform: The output waveform looks like the previous waveform,
but is only made out of lines thinner than the first output.
c. Generate polar coordinate (z) of complex grid using the command cplxgrid with 30
grids. Display the complex functions using cplxmap command.
Syntax:
a.
>> z=cplxgrid(30);
>> x=(z.^5).^(1/8);
>> cplxmap(z,x);
Describe the output waveform: The output waveform looks like a funnel painted in color
palettes.
b.
>> x=atan(2*z);
>> cplxmap(z,x);
Describe the output waveform: The output waveform looks like a steep waterfalls with
sharp edges.