<<

Revision 3

EE354 Lab 1: and Transforms – Theory, Simulations, and Measurements

Objective: Create and analyze the content of several signals, then see how well the theory follows simulation.

Pre-Lab: Theory

Using the Fourier Series table in Appendix I (attached at the end of this lab), determine the magnitude of the Fourier series coefficients an or bn for each of the following three signals by filling in the tables below (Hint: a “for loop” in Matlab would be an excellent way to do this quickly). Normalize the values to the magnitude of the a1 or b1 coefficient.

Signal 1: A 200 kHz square that ranges from -0.5 Volt to +0.5 Volt. Signal 2: A 200 kHz that ranges from 0 Volt to +1 Volt. Signal 3: A 200 kHz triangular wave that ranges from 0 Volt to +2 Volts.

Square Wave—Theoretical Results

Associated Normalized an n an Frequency Magnitude a1 0 1 2 3 4 5 6 7

Sawtooth Wave—Theoretical Results

Associated Normalized bn n bn Frequency Magnitude b1 0 – – – 1 2 3 4 5 6 7

1 Revision 3

Triangular Wave—Theoretical Results

Associated Normalized an n an Frequency Magnitude a1 0 1 2 3 4 5 6 7

In the space below, sketch magnitude frequency spectrum of each signal (remember, graphs have axes, labels, and titles).

|S(f)|

2 Revision 3

|S (f)|

Using Parseval’s Theorem, determine the power in each of the three using the first 7 terms from the Fourier Series. Calculate the power in dBm based on a 50Ω resistive load. As part of your report, compare these to the results from Matlab.

Theoretical Power in Each Waveform Power

Square Wave

Sawtooth Wave

Triangle Wave

------End of Pre Lab------

3 Revision 3

Lab Part 1: Simulation

Using Matlab, generate each of the original three waveforms and compare them against the Fourier Series representation that contains 1, 3, 5, and 7 terms. As the number of terms in the summation increases, you should observe that the approximation to the original waveform improves dramatically.

Because Matlab is an inherently discrete-time environment, the crucial first step is to set up properly your time vector. We have not yet discussed the sampling theorem (but we will!), but the very first thing you should do (before writing a single line of Matlab code) is to answer the following two questions: (1) what is my sampling frequency and (2) what should my sampling frequency be?

The answer to that question (for this lab only) is: fS = 2.0 MHz

To generate your time vector, the preferred method is:

T_stop = ######; % Replace XXXX with an actual number based on how much waveform % you want to see. A few cycles are usually good. f_s = ######; % Replace XXXX with the actual sampling frequency T_s = 1./f_s; t = 0:T_s:T_stop

To generate each of the original , you will need to use two new Matlab commands: square and sawtooth. These commands operate in a manner very similar to sin and cos for generating signals.

To generate the square wave, the Matlab command is:

s = A.*square(2.*pi.*fc.*t)

Where A is the desired of the square wave, fc is the desired center frequency, and t is your time vector (re-read the paragraph above about the sampling frequency). Executing this command should produce a nice square wave at the desired frequency and amplitude.

To generate the sawtooth and , we need to use the Matlab sawtooth command:

s = A.*sawtooth(2.*pi.*fc.*t, W)

Where A is the desired amplitude of the triangle wave, fc is the desired center frequency, and t is your time vector (re-read the paragraph above about the sampling frequency). W in this case is the “width” of the sawtooth waveform. A width of W = 1.0 produces a sawtooth waveform, and a width of W = 0.5 produces a triangle wave. Executing these commands should produce a nice sawtooth/triangle wave at the desired frequency and amplitude.

4 Revision 3

Plot the time-domain representation of each waveform to include the original plus the Fourier series representation with 1, 3, 5, and 7 terms. Additionally, plot the frequency spectrum associated with the original signal and the spectrum from the 7 term Fourier Series representation. The time-domain signal should show several cycles of the sinusoid, and the spectrum should be plotted as linear magnitude and show all relevant .

NOTE 1: The provided Matlab code below uses the FFT (Fast Fourier Transform) routine to generate the power spectrum of a given signal−specifically the spec_analysis.m function available on the course website. The FFT only displays the spectral content of a signal that falls below half the sampling frequency. Additionally, the spec_analysis.m function provides power in dBm for a particular load impedance. To solve for normalized power, use a 1Ω impedance. To get to amplitude (which is what we need for the results), we have to first convert back from dBm to Watts, and then Watts back to Volts (Amplitude).

Ultimately, we want to be able to compare all three signals at the same (or similar) effective sampling frequency. To correctly generate and display all shifted copies of your spectrum, use code similar to the following snippet:

s = A.*square(2.*pi.*fc.*t); % Original Signal, Sampled at Original Rate impedance = ######;

[freq,power] = spec_analysis(s,fs,impedance); % Generate the Spectrum plot(freq,power) % This plots the results in dBm!

NOTE 2: For all of your displays, the frequency spectrum will have power given in dBm. To properly display the signal you are interested in, you must first undo the dB conversion. Further, you must adjust the axes to a reasonable set of bounds. To do that, run the following commands to "zoom" in on a section of your plots before you print them or save them.

% sets the min and max power/amplitude values displayed in the plot min_power = ######; max_power = ######;

% sets the min and max displayed in the plot min_freq = ######; max_freq = ######;

% sets the min and max frequency displayed in the plot...all freqs will be % displayed, adjust as necessary to get the appropriate range axis([min_freq max_freq min_power max_power]) grid on

5 Revision 3

Square Wave—Matlab Results Normalized Associated | an | an n Magnitude Frequency (Observed) a (Observed) 1 0 XXXXXXXXXX XXXXXXXXX XXXXXXXXXXXX 1 2 3 4 5 6 7

Sawtooth Wave— Matlab Results Normalized Associated | bn | bn n Magnitude Frequency (Observed) b (Observed) 1 0 XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX 1 2 3 4 5 6 7

Triangular Wave— Matlab Results Normalized Associated | an | n Magnitude Frequency (Observed) (Observed) 0 XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX 1 2 3 4 5 6 7

6 Revision 3

Appendix A: Fourier Series Coefficients Table

Note: In this table, the an values are associated with the cosine terms; the bn values are associated with the terms.

7