Week 3 Homework

a.  Using Octave, generate a signal, x(t), as shown below along with its components. Assume a sampling frequency (fs) of 8000 second. Similar to Figure 3-2 a, you should plot the individual components (e.g. component 1 = sin(2π2000t), component 2 = 0.6 sin(2π1000t + π/4 and component 3 = + 0.2 sin(2π1000t -3π/4) along with the composite signal. Similar to Figure 3-2, you should also illustrative each component as a “continuous” signal to provide a better view of the forms of the resultant waves.

x(t) = sin(2π2000t) + 0.6 sin(2π1000t + π/4) + 0.2 sin(2π1000t -3π/4)

Be sure to include, axis labels, legends, and a title on your plot.

Below is one possible outcome that would satisfy the plotting requirements. Notice, the discrete data points for each of the components and composite signal are shown along with a higher resolution more continuous waveform. (Hint: To make the continuous looking waves just show more data points, in Octave this could be: n=0:0.1:7 as opposed to n=0:7). I differentiated the discrete and continuous-like lines by using “C” to indicate continuous.

b.  Similar to Figures 3-2 b-d, use Octave to generate and plot the composite signal, along with the 1KHz sinusoids for m=1, m=2 and m=3. Be sure to include, axis labels, legends, and a title on your plot. Below is one possible outcome that would satisfy the plotting requirements for m=2. Notice the Signal will be the same on all plots. You will be including the Octave code to generate the plots for m=1, m=2 and m=3 sinusoids.

c.  Using Octave, apply equation 3-3 to generate an 8-point DFT on x(t). You should provide an output table showing the magnitude and phase (in degrees) for each of the 8 points. The table below shows a possible result.

M / Magnitude / Phase (degrees)
0 / 0.00000 / 0
1 / 1.60000 / -45
2 / 4.00000 / -90
3 / 0.00000 / 0
4 / 0.00000 / 0
5 / 0.00000 / 0
6 / 4.00000 / 90
7 / 1.60000 / 45

Hint: Octave, Matlab and many software products are very precise in their calculations (although you may wonder about this when you use it). What happens is values very close to 0 will be displayed as very small numbers as opposed to 0. For example, you may see 3.245 e-16. For our purposes, this is really zero. But when this value is used to calculate phase along with another really small number, you will find the phase values are not correct. So, one work around is to use a tolerance parameter to remove this issue. In Octave, something like this works:

% Adjust for tolerance checking for small values and making them zero.

% Note I am using Octave functions to take the real and imaginary parts of a complex number

tol=1e-10;
rt = real(q);
it = imag(q);
if ( abs(rt) < tol)
rt = 0;
end
if (abs(it) < tol)
it = 0;
end
final=complex(rt,it) ;

A couple more hints for this one. Use the following the calculate magnitude and phase in Octave:

% Assuming final is the X(m) then this gives you the magnitude:
mag=abs(final);

% And this gives you the phase in degrees
phase=angle(final)*180/pi;

d.  Shift the x(t) signal by 5 positions forward and rerun the Octave routine to generate an 8-point DFT. Show your original and shifted signal along with an output table showing the magnitude and phase (in degrees) for each of the 8 shifted points. The table below shows a possible result.

M / Magnitude / Phase (degrees)
0 / 0.00000 / 0
1 / 1.60000 / 90
2 / 4.00000 / 180
3 / 0.00000 / 0
4 / 0.00000 / 0
5 / 0.00000 / 0
6 / 4.00000 / 180
7 / 1.60000 / -90

Compare the results of the original 8-point DFT with the elements shifted by 5. Comment on the results of the shift and its impact on the DFT. Be sure to discuss any changes in magnitude and phase. Using equations 3-19 and 3-22 to justify the phase differences you observed.

Hint: In octave, You can use:

xsumshift = shift(xsum,3);

to shift a vector 3 elements forward.

e.  Using the output from the original DFT in part c, use Octave to run an Inverse DFT. Show that the results from the inverse DFT and original x(t) values are the same. You can demonstrate they are the same by side by side comparisons in a table or a plot.

Deliverables: You should include one Octave m file that solves all of the above parts for this homework. You should name it yournamehw3.m. Be sure your m file works without issue and accurately provides the outputs and plots as needed for this assignment. Note: your octave m files should do all of the work for you. In other words, no hard-coding values, generate your signals and perform the analysis and plotting all using Octave.

Your word document should be named yournamehw3.doc (or yournamehw3.docx) and will include analysis and discussions supporting your results.

Be sure to submit your homework in the WebTycho assignments folder no later than the due date listed in the syllabus.

3