EXPERIMENT 3: WHITE GAUSSIAN NOISE 1) OBJECTIVE • To

advertisement
EXPERIMENT 3:
WHITE GAUSSIAN NOISE
1) OBJECTIVE
 To study the delta function in both time and frequency domains
 To obtain the autocorrelation and power spectral density of MATLAB generated
White Gaussian Noise (WGN)
 To obtain the pdf of WGN
 To download MATLAB generated WGN into the Agilent E4438C vector signal
generator
2) LAB WORK
1. Copy the experiment file.
2. Examine and then run the file using MATLAB; note that three figures are generated.
3. In the first figure, observe that the FFT (Fast Fourier Transform) of delta function is
flat.
4. In the second figure, autocorrelation and power spectral density of MATLAB
generated White Gaussian Noise (WGN) are given.
5. In the third figure, the pdf of WGN is seen.
6. Study these figures thoroughly, while recording them in your lab report.
7. After the observations, identify in the m file the sections (by line numbers) that
produce the above mentioned three figures.
8. At the end of this m file, the time variations of noise signal (the upper figure in Figure
3) is generated with the name “noise_waveform”.
9. Download the “noise_waveform” into Agilent E4438C vector signal generator:
a. In the Windows Internet Explorer, set the IP address to 10.10.96.185.
b. Press the Signal Generator FTP Access and choose the directory of
BBG1/WAVEFORM.
c. Ensure that CH1 of the Agilent DSO6034A oscilloscope is connected to I (or
Q) output located at the rear of the signal generator.
d. On the vector signal generator, press Mode Setup under the MENUS. Then
press Dual ARB soft key on the right menu. After that, press Select
Waveform using the soft key on the right of the screen. Using the arrow keys
near the numeric keypad select the MATLAB generated “noise_waveform”
and press Select Waveform soft key. From the right menu, set ARB selection
to On. From Mode Setup, ARB Setup, make sure that ARB Sample Clock is
at 100 MHz and IQ Mode Filter is at 40 MHz. After performing these steps,
the replica of the noise time waveform observed as MATLAB Figure 3 should
appear on the oscilloscope screen on CH1.
Note 1: During the successive downloads, remember to delete the existing file of the
same name in this directory, otherwise FTP connection to the signal generator will be
blocked.
Note 2: During the successive downloads, remember to set ARB selection to Off,
otherwise FTP connection to the signal generator will be blocked.
1 10. Connect one of the remaining I or Q ( I or Q ) from the rear panel of Agilent E4438C
vector signal generator to the Agilent E4407B Spectrum Analyzer. By using
FREQUENCY Channel button on the spectrum analyzer, set center frequency to 0
MHz, start frequency to –60 MHz, stop frequency to 60 MHz. By using Amplitude Y
scale, adjust attenuation to 0 dB, Ref. level to –10 dBm. You can try this step for
different attenuation values like 20 dB.
11. Initially set var (variance of noise power) in MATLAB m file to –20 (dBW), then by
equating n (the number of noise samples used for Figure 3) to 100, 1000, 10000,
100000, 1000000, measure the rms values of noise waveform on the oscilloscope and
record these readings in your lab report.
12. Use the spectrum analyzer for the same values of n and by pressing Measure,
Channel Power, take readings of Occupied BW, Channel Power and Power Spectral
Density.
13. Repeat the above readings for var = –15, –10, –5, 0. Tabulate these results and record
them in your lab report.
14. Include in your lab report, the general comments and a description of what you have
learned from this experiment.
2 MATLAB CODE
% This program attempts to verify that the frequency spectrum of White Gaussian Noise is white (i.e. flat)
% First, study the delta function. This is one and a (large) number of zeros
close all; clear all; clc; clf
n = 1000; xt_delta = [ones(1,1) zeros(1,n)]; figure(1)
subplot(2,1,1); plot(1:length(xt_delta),xt_delta,'LineWidth',4,'Color','green')
xlabel('t (Time)','FontSize',12,'FontWeight','bold');
ylabel('Amplitude','FontSize',12,'FontWeight','bold');
title('Delta Function','FontSize',12,'FontWeight','bold')
axis ([-15 n 0 1.1]); set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
Xf_delta = fft(xt_delta,512); Power_Xf = Xf_delta.* conj(Xf_delta) / 512;
Power_Xf = Power_Xf / max(Power_Xf); f = 1000*(0:256)/512;
subplot(2,1,2); plot(f,Power_Xf(1:257),'LineWidth',4,'Color','Red');
axis ([-(max(f)-min(f))*0.05 max(f)*1.1 0 1.1]);
xlabel('f (Frequency)','FontSize',12,'FontWeight','bold');
ylabel('Amplitude','FontSize',12,'FontWeight','bold');
title('Fourier Transform of Delta Function','FontSize',12,'FontWeight','bold')
set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
% Whiteness of White Gaussian Noise
% As n (number of noise samples) and no_run are increased, uniformity increases
n = 1000; m = 1000; no_run = 100;
% m should be the same as n, otherwise correlation deviates towards the edges
rn_tot=zeros(1,2*m-1);
for j=1:no_run,
noise = wgn(1,n,0.01);
rn = xcorr(noise,m-1,'unbiased');
rn_tot = rn_tot + rn;
end;
rn_tot = rn_tot/no_run; figure(2)
subplot(2,1,1); plot(-m+1:m-1,rn_tot)
xlabel('\tau (Time)','FontSize',12,'FontWeight','bold');
ylabel('Normalized Amplitude','FontSize',12,'FontWeight','bold');
title('Autocorrelation of WGN','FontSize',12,'FontWeight','bold')
set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
noise_spect = fftshift(abs(fft(rn_tot)));
subplot(2,1,2); plot(-m+1:m-1,noise_spect);
xlabel('f (Frequency)','FontSize',12,'FontWeight','bold');
ylabel('Normalized Power Density','FontSize',12,'FontWeight','bold');
title('Power Spectrum of WGN','FontSize',12,'FontWeight','bold');
set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
% The pdf of White Gaussian Noise
% n is the number of noise samples and var (variance) is the noise power in dBW
n = 1000000; var = -10; noise = wgn(1,n,var); figure(3)
subplot(2,1,1); plot(1:n,noise);
xlabel('t (Time)','FontSize',12,'FontWeight','bold');
ylabel('Amplitude','FontSize',12,'FontWeight','bold');
title('Time Variation of White Gaussian Noise','FontSize',12,'FontWeight','bold');
set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
[nn,xout] = hist(noise,50);
subplot(2,1,2); bar(xout,nn/n);
xlabel('Amplitude','FontSize',12,'FontWeight','bold');
ylabel('Noise pdf','FontSize',12,'FontWeight','bold');
set(gcf,'Color',[1 1 1]); set(gca,'FontSize',16);
3 % Constructing the noise waveform to be loaded into ESG 4438C vector signal generator
% Note that both I and Q are identical in this case
waveform(1:2:2*length(noise)) = noise;
waveform(2:2:2*length(noise)) = noise;
waveform = waveform / max(abs(waveform));
waveform = round(32767*waveform);
waveform = uint16(mod(65536 + waveform,65536));
if strcmp( computer, 'PCWIN' )
waveform = bitor(bitshift(waveform,-8),bitshift(waveform,8));
end
filename = 'C:\MATLAB7\work\noise_waveform';
[FID, message] = fopen(filename,'w'); % Open a file to write data
if FID == -1 error('Cannot Open File'); end
fwrite(FID,waveform,'unsigned short');
% write to the file
fclose(FID);
4 
Download