ES440. Lab 1- MATLAB Time Domain and Frequency Domain Signal Representation MATLAB Exercises: M1- Assume S1(t) = 10cos(2θ) in Volts represents the voltage signal and S2(t) = 5cos(2θ) in Amps represents the current signal. Let’s say (θ) ranges from 0 to 2Pi. 1- Plot S1, S2, Instantaneous power, average power, S1, and S2 all on one plot. Make sure you label all the plots properly or your plots have legends. HINT: it is possible to take the integral over a specific range using trapz(theta,function). This will be useful to calculate the average power. 2- What exactly is the Average Power? 3- What happens to the average power if (θ) ranges from 0 to 4Pi. 4- What is the frequency difference between the instantaneous power and S1 and S2? Explain why. 5- Assume the current signal is shifted by 90 degrees. Using a plot compare the instantaneous power when with and without shift in the current signal. Explain what happens. M2 – A simple way to generate random noise on a signal (S1) is to use the following function: sigma*randn(size(signal)). In this case the value of Sigma indicates the strength of the noise signal. Note that the power of the noise and signal can be calculated by taking the variance waveformPower = var(signal). You can also play the waveform using sound() function. frequency = 1000; duration = 1; amplitude = 1; sampleFreq = 48000; ta = linspace( 0, duration, duration * sampleFreq ); signal = amplitude * sin( 2 * pi * frequency * ta ); sigma = 0.91; %noise standard deviation noise = sigma*randn(size(signal)); % noise in volt signal_and_noise = signal+noise; %noisy signal sound( YourWaveform, sampleFreq ); Using the above code answer the following questions: 1- Plot the signal waveform for several periods (without any noise). Do you hear it? 2- Plot the waveform for several periods when noise and signals are both ADDED, as shown above. Assume sigma = 0.2. Do you hear the noisy signal? 3- How does the waveform sound like? ES440 Lab#1 1 4- Calculate the SNR in dB. Show your Matlab code for this part. 5- What happens to the generated waveform if we MULTIPLY the noise and signal? M3- Read the help on Sa( ) function. The sinc( ) function is a common signal in communication systems. The code below shows how to plot a sinc ( ) function. f = -10:0.1:10; T = 1; x = pi*T*f+0.001; YourSinc = T*SA(x); 1- Plot the sinc () signal as a function of frequency. 2- It is possible to plot the magnitude and phase of the sinc function using the following: B = log(YourSinc) %note: log(z) = log(abs(z)) + i*atan2(y,x) WdB = (20/log(10))*real(B); Theta = (180/pi)*imag(B); 3- Plot the magnitude and phase of the sinc( ) function. You must use subplot. Your plot must also have grid lines. Note that this is how the signal appears on the spectrum analyzer (you do not see the negative frequencies) M4- In this section we would like to generate a switched Sinusoidal signal; see the textbook for more information. This is achieved by multiplying a square waveform and a sinusoidal waveform: fs = 100; t = 0:1/fs:1.5; Amp_shift = 1; x1 = sin(2*pi*100*t); x2 = Amp_shift+square(2*pi*10*t); 1- Let’s assume the frequency of the square waveform is 1KHz, with an amplitude of 1 volt peak-to-peak and offset of 0.5V.Let’s also assume the frequency of the sin () signal is 10 KHz with an amplitude of 2V peak-to-peak and no offset. 2- Using subplots, show all three signals. ES440 Lab#1 2 M5- In this section we like to understand how we can plot FFT of a signal. Below we have an example. Review the code very carefully. We will talk about the details of the code next week. clear; close all; N=2^13; % Number of samples fmax=6400; % Maximum frequency in Hz <-fs=2*fmax; % Sampling Frequency df=fs/N;% frequency spacing dt=1./(df.*N); % time spacing t=(1:N)*dt-dt % time samples f(1:N/2)=(1:N/2)*df-df; % Nonnegative frequency samples f(N/2+1:N)=-fmax+(0:N/2-1)*df; % Negative frequency samples f2=fftshift(f); % shifting the values in f xt = s(t) % Your signal is here! xf=fft(xt).*dt; xf= 20*log10(fftshift(abs(xf))); % converting to dB, plot(f2,xf,'LineWidth',2); to plot |W(f)| plot(t,xt,'LineWidth',2); to plot the signal s(t) 1- Plot the following signal in time domain: s(t) = sin(2*pi*f*t)* sin(2*pi*4f*t). 2- Plot the FFT of s(t). Explain what exactly is happening. 3- Assuming we have Pulse = rectpuls(t,0.01), what will be the FFT of the Pulse signal? Show the results. How does it look like? You can only show the positive frequencies. M6- Last summer, I was testing a backplane board. I connected my scope to a test point and I saw a very strange signal. I started recording the measured points from the scope so I can show it to my boss (download the test points). To my surprise, my boss used Matlab to plot all the points generated by the scope. He looked at signal in his office and he said: “Ha! This is exactly what I thought is happening! Just clean up the signal!” I had no clue what he was talking about! He told me to apply Fourier analysis to the signal to understand what is happening. 1- Plot the points in the file using Matlab. This is the time representation of the signal as shown in the scope. Note that the first column of the file contains the time values and the second column represents the measured data points on the scope. 2- Apply Fourier analysis to the recorded signal. Plot the spectrum of the signal in Hz and dB (HINT: see the previous section of this lab). 3- Explain exactly what is happening (HINT: discuss it with each other!) Here is a simple way to plot values from a file: input_file= importdata('filename.txt'); column1 = input_file(:,1); column2 = input_file(:,2); Now do you understand why we are so concern about Fourier analysis and signal spectrum? J ES440 Lab#1 3