Communications II Experiment IV COMMUNICATIONS II EXPERIMENT 4 Group member 1 Name: Number: Group member 2 Name: Number: 1. OBJECTIVES Fourier Transforms and Convolution Related to Delta Function Improving SNR of a signal within broadband noise 2. BASIC INFORMATION 2.1 Delta Function The impulse δ(t) is defined to be equal to zero for all t≠ 0 by the requirement that its integral be unity. The discrete time counterpart of δ (t) is the (discrete) delta function While there are a few subtleties (i.e., differences) between δ(t) and δ[k], for the most part they act analogously. For example, the program specdelta.m given below and included in your exp4 folder calculates the spectrum of the (discrete) delta function. % specdelta.m plot the spectrum of a delta function time=2; % length of time Ts=1/100; % time interval between samples t=Ts:Ts:time; % create time vector x=zeros(size(t)); % create signal of all zeros x(1)=1; % delta function plotspec(x,Ts) % draw waveform and spectrum The output of specdelta.m is shown in Figure 1. As expected from the discussions from the class, the magnitude spectrum of the delta function is equal to 1 at all frequencies. 1 Communications II Experiment IV Figure 1: A (discrete) delta function at time 0 has a magnitude spectrum equal to 1 for all frequencies. 1 amplitude 0.8 0.6 0.4 0.2 0 0 0.2 0.4 0.6 0.8 1 1.2 seconds 1.4 1.6 1.8 2 0 -50 -40 -30 -20 -10 0 10 frequency 20 30 40 50 magnitude 2 1.5 1 0.5 2.2 Convolution Matlab has several functions that simplify the numerical evaluation of convolutions. The most obvious of these is conv, which is used in convolex.m given below and included in exp4 folder. convolex.m calculates the convolution of an input x (consisting of two delta functions at times t = 1 and t = 3) and a system with impulse response h that is an exponential pulse. The convolution gives the output of the system. % convolex.m: example of numerical convolution Ts=1/100; time=10; % sampling interval and total time t=0:Ts:time; % create time vector h=exp(-t); % define impulse response x=zeros(size(t)); % input is sum of two delta functions x(1/Ts)=3; x(3/Ts)=2; % at times t=1 and t=3 y=conv(h,x); % do convolution subplot(3,1,1), plot(t,x) ylabel('input') subplot(3,1,2), plot(t,h) ylabel('impulse response') subplot(3,1,3), plot(t,y(1:length(t))) ylabel('output') xlabel('time in seconds') Figure 2 shows the input to the system in the top plot, the impulse response in the middle plot, and the output of the system in the bottom plot. Nothing happens before time t = 1, and the output is zero. When the first spike occurs, the system responds by jumping to 3 and then decaying slowly at a rate dictated by the shape of h(t). The decay continues smoothly until time t = 3, when the second spike enters. At this point, the output jumps up by 2, and is the sum of the response to the second spike, plus the remainder of the response to the first spike. Since there are no more inputs, the output slowly dies away. 2 Communications II Experiment IV Figure 2: The convolution of the input (the top plot) with the impulse response of the system (the middle plot) gives the output in the bottom plot. . input 3 2 1 impulse response 0 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 time in seconds 7 8 9 10 1 0.5 0 output 3 2 1 0 2.2 Improving SNR We have described several kinds of corruption that a signal may encounter as it travels from the transmitter to the receiver. In most of the cases linear filters can help. Perhaps the simplest way a linear bandpass filter can be used is to remove broadband noise from a signal. A common way to quantify noise is the signal-to-noise ratio (SNR) which is the ratio of the power of the signal to the power of the noise at a given point in the system. If the SNR at one point is larger than the SNR at another point, then the performance is better because there is more signal in comparison to the amount of noise. For example, consider the SNR at the input and the output of a BPF as shown in Figure 3. The signal at the input (r(t) in part (a)) is composed of the message signal x(t) and the noise signal n(t), and the SNR at the input is therefore Similarly, the output y(t) is composed of a filtered version of the message (yx(t) in part (b)) and a filtered version of the noise (yn(t) in part (b)). The SNR at the output can therefore be calculated as Observe that the SNR at the output cannot be calculated directly from y(t) (since the two components are scrambled together). But, since the filter is linear, which effectively shows the equivalence of parts (a) and (b) of Figure 3. 3 Communications II Experiment IV Figure 3: Two equivalent ways to draw the same system. In part (a) it is easy to calculate the SNR at the input, while the alternative form (b) allows easy calculation of the SNR at the output of the BPF. The Matlab program improvesnr.m given below and included in your exp4 folder explores this scenario concretely. The signal x is a bandlimited signal, containing only frequencies between 3000 and 4000 Hz. This is corrupted by a broadband noise n (perhaps caused by an internally generated thermal noise) to form the received signal. The SNR of this input snrinp is calculated as the ratio of the power of the signal x to the power of the noise n. The output of the BPF at the receiver is y, which is calculated as a BPF version of x+n. The BPF is created using the firpm command. To calculate the SNR of y, however, the code also implements the system in the alternative form of part (b) of Figure 3. Thus, yx and yn represent the signal x filtered through the BPF and the noise n passed through the same BPF. The SNR at the output is then the ratio of the power in yx to the power in yn, which is calculated using the function pow.m, available in your exp4 folder. % improvesnr.m: using linear filters to improve SNR close all clear all time=3; Ts=1/20000; % length of time and sampling interval freqs=[0 0.29 0.3 0.4 0.41 1]; amps=[0 0 1 1 0 0]; b=firpm(100,freqs,amps); % BP filter n=0.25*randn(1,time/Ts); % generate white noise signal x=filter(b,1,2*randn(1,time/Ts)); % bandlimited signal between 3K and 4K y=filter(b,1,x+n); % (a) filter the received signal+noise yx=filter(b,1,x); yn=filter(b,1,n); % (b) filter signal and noise separately z=yx+yn; % add them diffzy=max(abs(z-y)) % and make sure y and z are equal snrinp=pow(x)/pow(n) % SNR at input snrout=pow(yx)/pow(yn) % SNR at output % check spectra figure,plotspec(x+n,Ts) figure,plotspec(y,Ts) 4 Communications II Experiment IV Since the data generated in improvesnr.m is random, the numbers are slightly different each time the program is run. Using the default values, the SNR at the input is about 7.8, while the SNR at the output is about 61. This is certainly a noticeable improvement. The variable diffzy shows the largest difference between the two ways of calculating the output (that is, between parts (a) and (b) of Figure 3). This is on the order of 10-15, which is effectively the numerical resolution of Matlab calculations, indicating that the two are (effectively) the same. Figure 4 and 5 plot the spectra of the input signal plus noise and output of the BPF respectively. Observe the large noise floor in Figure 4, and how this is reduced by passage through the BPF. Observe also that the signal is still changed by the noise in the pass band between 3000 and 4000 Hz, since the BPF has no effect there. The program improvesnr.m can be thought of as a simulation of the effect of having a BPF at the receiver for the purposes of improving the SNR when the signal is corrupted by broadband noise, as was described Figure 4: The spectrum of the input to the BPF 4 amplitude 2 0 -2 -4 0 0.5 1 1.5 seconds 2 2.5 3 magnitude 2000 1500 1000 500 0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 frequency 0.4 0.6 0.8 1 4 x 10 5 Communications II Experiment IV Figure 5: The spectrum of the output of the BPF 4 amplitude 2 0 -2 -4 0 0.5 1 1.5 seconds 2 2.5 3 magnitude 2000 1500 1000 500 0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 frequency 0.4 0.6 0.8 1 4 x 10 3. EXPERIMENT Copy exp4 folder to your computer, start Matlab and change the directory of Matlab to exp4. 3.1 Fourier Transforms Related to Delta Function Type “specdelta” in Matlab command window and make sure you can observe Figure 1. Find the spectrum of the discrete delta function where the delta does not occur at start of x where x[10]=1. (That means x=zeros(size(t)); x(10)=1). copy your result into Fig 5. Repeat for x[100]=1. Copy your result into Fig 6. Repeat for x[110]=1. Copy your result into Fig 7. Does the magnitude of the spectrum change when there is a shift in time domain Answer: You will change the magnitude and observe the effect in the spectrum. Change x[1]=10 (That means x=zeros(size(t)); x(1)=10). Find the spectrum. Copy your result into Fig 8. Repeat for x[10]=3. Copy your result into Fig 9. Repeat for x[110]=0.1. Copy your result into Fig 10. How does the spectrum change when magnitude of x changes. Answer: You will now observe the spectrum of a signal containing two delta functions. Create a signal containing two delta functions at the start and in the end, x[1]=1 6 Communications II Experiment IV and x[end] =1. (That means x=zeros(size(t)); x(1)=1; x(end)=1). Find the spectrum. Copy your result into Fig 11. Repeat for x[90]=1 and x[end-90]=1. Copy your result into Fig 12. Repeat for x[33]=1 and x[120]=1. Copy your result into Fig 13. Train of impulses in time domain corresponds to train of impulses in frequency domain. x=zeros(size(t)); x(1:20:end)=1 produces train of impulses 20 samples apart. Find the spectrum in this case and copy your result into Fig 14. Repeat when impulses are 25 samples apart. copy your result into Fig 15. How does the spectrum change when the train of impulses are separated more in time Answer: 3.2 Convolution Type “convolex” in Matlab command window and make sure you can observe Figure 2. Find the output when input is a delta function at t=4 given by x=zeros(size(t)); x(4/Ts)=2 and the impulse response is a square wave with duration T=1sec given by h=zeros(size(t)); h(1:1/Ts)=1; Copy your result into Fig 16. Find the output when input is two delta functions at t=1 with magnitude 3 and t=5 with magnitude 5 and the impulse response is a square wave with duration T=2sec and magnitude is 4. Copy your result into Fig 17. Find the output when input is three delta functions at t=2 with magnitude 1 and t=5 with magnitude 2 and t=7 with magnitude 3 and the impulse response is a square wave with duration T=1sec and magnitude is 1. Copy your result into Fig 18. . Find the output when input is square wave with duration T=1sec and magnitude is 1 and the impulse response is a square wave with duration T=1sec and magnitude is 1. Copy your result into Fig 19. 3.3 Improving SNR Type “improvesnr” in Matlab command window and make sure you can observe Figure 3-4 and in command window diffzy is close to zero, snrinp is around 8, and snrout is around 60. Also find snrout/snrinp and copy the results below. Answer: diffzy= snrinp= snrout= snrout/ snrinp= Change improvesnr so that input is a signal between 2K and 4K. Copy your result into Fig 20. Also copy the result of diffzy, snrinp, snrout, snrout/snrinp below. Answer: diffzy= snrinp= snrout= snrout/ snrinp= 7 Communications II Experiment IV Change improvesnr so that input is a signal between 2K and 6K. Copy your result into Fig 21. Also copy the result of diffzy, snrinp, , and snrout below. Answer: diffzy= snrinp= snrout= snrout/ snrinp= How does snrout/snrinp change when bandwidth of the signal increases. Explain why Answer: 8 Communications II Experiment IV 4. RECORDS Figure 5 Figure 6 Figure 7 9 Communications II Experiment IV Figure 8 Figure 9 Figure 10 10 Communications II Experiment IV Figure 11 Figure 12 Figure 13 11 Communications II Experiment IV Figure 14 Figure 15 Figure 16 12 Communications II Experiment IV Figure 17 Figure 18 Figure 19 13 Communications II Experiment IV Figure 20 Figure 21 14