EECS 307 Matlab Assignment 1 The purpose of this assignment is to illustrate properties of some elementary waveforms and filters in time and frequency using Matlab functions. Example 1: Single Sinusoidal Signal 1a. Generate a sinusoidal signal using the Matlab function gen_sin.m with the following parameters: Amplitude = 100, frequency = 100Hz, initial_phase = 0, sample rate = 5000, signal duration (T) = 1 sec. Note that Matlab generates sin(2*pi*f*n/r + init_phase), where r is the sample rate (number of samples per second), n is the time index, and f is the frequency in cycles per second. 1b. Plot two cycles of the signal in time with the appropriate time scale. Plot the magnitude of the signal in the frequency domain using the Matlab command: sig_freq = fft(sig_time). Here sig_time is the time array and sig_freq is a vector containing the sampled Fourier Transform. The samples in frequency are evenly spaced from f = -r/2 to f = r/2. The first half of the vector (elements 1 through r*T/2) contain samples of the frequency from f = 0 to r/2, and the latter half of the vector contain samples of the frequency from f = –r/2 to 0. Verify that the amplitude shown in frequency is consistent with the time-domain waveform. (Hint: Because of the finite resolution in frequency, the delta functions in frequency appear as narrow rectangles. What is the area in each rectangle?) Example 2: Multiple Sinusoids Add another sinusoid with frequency 1000 Hz and amplitude 100 to the one generated in Example 1. (All other parameters are the same.) Plot two cycles of the sum of the two signals in time, and plot the magnitude of the Fourier Transform. Verify that the magnitudes of the peaks in frequency are consistent with the time domain waveform. Example 3: Filtering The following matlab routine computes the output of a low-pass Butterworth filter: [output, H_low, h_low] = low_pass(input, cutoff, sample_rate, N); input is the vector of input samples; output is the vector of output samples; cutoff is the cutoff frequency of the filter; sample_rate is the sampling rate r (samples per second); N is the order of the filter; h_low is the vector containing the samples of the impulse response with spacing 1/sample_rate; H_low is the vector containing the frequency response from f = –r/2 to f = r/2. The first half of the vector (elements 1 through r*T/2) contain samples of the frequency response from f = 0 to r/2, and the latter half of the vector contain samples of the frequency response from f = –r/2 to 0. Generate the output of a low-pass Butterworth filter with the signal generated in Example 2 as the input with the following parameters: Filter order N = 11 Cutoff frequency = 500 Hz Plot the filtered signal in the time domain (show a small number of cycles), and plot the corresponding Fourier Transform. Also plot the impulse response of the filter and the magnitude and phase of the filter transfer function. Explain the plots. Example 4: Square Wave 4a. Generate a sampled square wave with amplitude = 100 and frequency = 500Hz using the following matlab routine: input = gen_square(amplitude, frequency, sample_rate, T). Take the signal duration T = 1 and sample_rate = 20000. Plot 5 cycles of the generated signal in time and plot the magnitude of the Fourier Transform. Explain the frequency domain plot. 4b. Now pass the signal generated in 4a through a low-pass filter with cutoff frequency 1000 Hz. Plot the output in time and frequency (magnitude only), and explain your results. 4c. Pass the signal generated in 4a through a high-pass filter with cutoff frequency 1000Hz using the following matlab routine: [output, H_high, h_high] = high_pass(input, cutoff, sample_rate, N); where the parameters are analogous to those used in the low-pass filter previously defined. Plot the output in time and frequency, and explain your results. Also plot the impulse response of the high-pass filter, and the magnitude of the transfer function. 4d. Repeat parts 4b and 4c with cutoff frequency 5000 Hz. Explain the general behavior of the plots. Example 5: Modulation 5a. Generate two sinusoids with the following parameters: ampl1 = 100, freq1 = 100; ampl2 = 1, freq2 = 1000 For both sinusoids, sample_rate = 20000 (per second), signal duration=1s. The first signal is the desired (information) signal, and the second signal is the carrier. 5b. Multiply the two signals and plot 5 cycles of the generated signal in time. Plot the magnitude of the Fourier Transform. Example 6: Demodulation 6a. Generate a carrier signal with the same parameters as the second sinusoid in Example 5a, and multiply it with the modulated signal in part 5b. Plot 5 cycles of the generated signal in time domain, and plot the magnitude of the Fourier Transform. Explain the plots. 6b. Design a filter to recover the desired signal. Specify all parameters and show the filter output.