EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

14
CTU: EE 443 Communications 1: Lab 3: MATLAB Project Frequency Modulation / Detection and Noise 1 Colorado Technical University EE 443 Communication 1 Lab 2: MATLAB Project Frequency Modulation / Detection and Noise September 2010 Loren K. Schwappach ABSTRACT: This lab report was completed as a course requirement to obtain full course credit in EE443, Communication 1 at Colorado Technical University. Given a message and a carrier signal, this lab report uses MATLAB to demonstrate the process of frequency modulation and demodulation of the message using a VCO. All of the code mentioned in this lab report was saved as a MATLAB m-file for convenience, quick reproduction, and troubleshooting of the code. All of the code below can also be found at the end of the report as an attachment, as well as all figures. All of the code and images created for this report are authentic and of my sole content. Since I finished 90 percent of this lab ahead of my struggling peers I shared snippets of my code with a few students (Shawn Malone, and Crystal Brandy) to aid in their understanding of the this lab and assisted them in working through Simulink although they will need to provide their own lab reports with their own content. If you have any questions or concerns in regards to this laboratory assignment, this laboratory report, the process used in designing the indicated circuitry, or the final conclusions and recommendations derived, please send an email to [email protected] . All computer drawn figures and pictures used in this report are of original and authentic content. I. INTRODUCTION The purpose of this lab is to learn how to characterize a Frequency modulated (FM) signal mathematically and simulate the frequency modulation of an input signal using MATLABs Simulink software. This lab also serves as an introduction into the effects of noise on a system and how to plot noise in MATLAB. II. OBJECTIVES There are three tasks that need to be completed for this lab assignment. The first task is to frequency modulate a signal in MATLAB and plot the FM signal in the time and frequency domain, and then select values of Beta which can simulate narrow band (NB) FM, wideband (WB) FM, and an FM signal without a carrier (dropped carrier scenario). The second task is to frequency modulate a signal using a Voltage-Controlled Oscillator (VCO) in Simulink and then use a transfer function to simulate a slope detector circuit such that the slope detector output is a combination of FM and AM. The third and final tasks involves noise. First a noise signal is generated and graphed in MATLAB, next the autocorrelation function of the noise signal is created. Finally Simulink is used to show what happens to a sinusoidal signal after noise is added, and then removed via a low pass filter, next the signal is replaced with a square wave input, finally the signal is passed though a slope detector and analyzed. III. PROCEDURE / RESULTS The procedures used in this lab are illustrated by the included MATLAB code and Simulink diagrams in this report. 1. Part 1 FM Modulation in MATLAB To begin this lab a time vector tis created as well as the corresponding message and carrier signal components as shown bellow... % Generating Carrier, Message and Modulated wave Fc = 500; Ac = 2; Pc = 0; Fm = 25; Am = 1; Pm = 0; Beta = 0; fs = 5000; %sampling frequency ts = 1/fs; %sampling interval t = 0:ts:((1/Fm)*3); %time vector Next the components were put together to display our message wave and carrier wave as shown below..

description

EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

Transcript of EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

Page 1: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 1

Colorado Technical University EE 443 – Communication 1

Lab 2: MATLAB Project – Frequency Modulation / Detection and Noise

September 2010

Loren K. Schwappach

ABSTRACT: This lab report was completed as a course requirement to obtain full course credit in EE443, Communication 1 at Colorado Technical University. Given a message and a carrier signal, this lab report uses MATLAB to demonstrate the process of frequency modulation and demodulation of the message using a VCO. All of the code mentioned in this lab report was saved as a MATLAB m-file for convenience, quick reproduction, and troubleshooting of the code. All of the code below can also be found at the end of the report as an attachment, as well as all figures. All of the code and images created for this report are authentic and of my sole content. Since I finished 90 percent of this lab ahead of my struggling peers I shared snippets of my code with a few students (Shawn Malone, and Crystal Brandy) to aid in their understanding of the this lab and assisted them in working through Simulink although they will need to provide their own lab reports with their own content.

If you have any questions or concerns in regards to this laboratory assignment, this laboratory report, the process used in designing the indicated circuitry, or the final conclusions and recommendations derived, please send an email to [email protected]. All computer drawn figures and pictures used in this report are of original and authentic content.

I. INTRODUCTION

The purpose of this lab is to learn how to

characterize a Frequency modulated (FM) signal

mathematically and simulate the frequency modulation of an

input signal using MATLABs Simulink software. This lab also

serves as an introduction into the effects of noise on a system

and how to plot noise in MATLAB.

II. OBJECTIVES

There are three tasks that need to be completed for

this lab assignment.

The first task is to frequency modulate a signal in

MATLAB and plot the FM signal in the time and frequency

domain, and then select values of Beta which can simulate

narrow band (NB) FM, wideband (WB) FM, and an FM signal

without a carrier (dropped carrier scenario).

The second task is to frequency modulate a signal

using a Voltage-Controlled Oscillator (VCO) in Simulink and

then use a transfer function to simulate a slope detector

circuit such that the slope detector output is a combination of

FM and AM.

The third and final tasks involves noise. First a noise

signal is generated and graphed in MATLAB, next the

autocorrelation function of the noise signal is created.

Finally Simulink is used to show what happens to a

sinusoidal signal after noise is added, and then removed via a

low pass filter, next the signal is replaced with a square wave

input, finally the signal is passed though a slope detector and

analyzed.

III. PROCEDURE / RESULTS

The procedures used in this lab are illustrated by the

included MATLAB code and Simulink diagrams in this report.

1. Part 1 – FM Modulation in MATLAB To begin this lab a time vector ‘t’ is created as well as the corresponding message and carrier signal components as shown bellow... % Generating Carrier, Message and Modulated wave

Fc = 500;

Ac = 2;

Pc = 0;

Fm = 25;

Am = 1;

Pm = 0;

Beta = 0;

fs = 5000; %sampling frequency

ts = 1/fs; %sampling interval

t = 0:ts:((1/Fm)*3); %time vector

Next the components were put together to display our message wave and carrier wave as shown below..

Page 2: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 2

m = Am*sin(2*pi*Fm*t + Pm); %message wave

c = Ac*sin(2*pi*Fc*t + Pc); %carrier wave

The final FM modulated signal is of the form..

st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM

signal

This frequency modulated signal was then plot in the time domain and in the frequency domain using various values of Beta needed to demonstrate NB, WB, and carrier missing FM as shown. % ------- B = .1 Beta = .1; st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM

signal % Plot of FM signal in Time Domain timePlot = figure; %gives graph window a name and

keeps it available plot (t,st); %plots FM signal in time domain title('FM Signal (B=.1) - Time domain'); %adds title

to graph xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,40e-3,-2,2]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 1: FM Signal, Beta = .1 in the time domain.

% Plot of FM Signal in Frequency Domain

[Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT

function

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (B=.1) - 2 Sided Spectrum') %adds

title to graph

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([-800,800,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 2: FM Signal Beta = .1 in the frequency domain.

Notice there are very few sideband frequencies making up

the message signal thus the low bandwidth (Narrowband)

% Plot of Modulated Wave in Frequency Domain - Close

Up

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (B=.1) - Pos Spectrum Closeup')

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([400,600,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 3: FM Signal Beta = .1 in the frequency domain

(Close-up). Notice there are very few sideband frequencies

making up the message signal thus the low bandwidth

(Narrowband)

Page 3: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 3

% ------- B = 5

Beta = 5;

st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM

signal

% Plot of FM signal in Time Domain

timePlot = figure; %gives graph window a name and

keeps it available

plot (t,st); %plots FM signal in time domain

title('FM Signal (B=5) - Time domain'); %adds title

to graph

xlabel('Time (s)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([0,40e-3,-2,2]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 4: FM Signal, Beta = 5 in the time domain.

% Plot of FM Signal in Frequency Domain

[Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT

function

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (B=5) - 2 Sided Spectrum') %adds

title to graph

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([-1000,1000,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 5: FM Signal Beta = 5 in the frequency domain.

Notice there are many sideband frequencies making up the

message signal thus the higher bandwidth (Wideband)

% Plot of Modulated Wave in Frequency Domain - Close

Up

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (B=5) - Pos Spectrum Closeup')

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([200,800,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 6: FM Signal Beta = 5 in the frequency domain

(close-up). Notice there are many sideband frequencies

making up the message signal thus the higher bandwidth

(Wideband)

Page 4: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 4

% ------- FM Signal with No Carrier

Beta = 1;

Ac = 0; %Carrier is no longer transmitting

st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM

signal

% Plot of FM signal in Time Domain

timePlot = figure; %gives graph window a name and

keeps it available

plot (t,st); %plots FM signal in time domain

title('FM Signal (No carrier) - Time domain'); %adds

title to graph

xlabel('Time (s)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([0,40e-3,-2,2]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 7: FM Signal with no carrier (Ac = 0). Without a

carrier you have no FM!

% Plot of FM Signal in Frequency Domain

[Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT

function

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (No carrier) - 2 Sided Spectrum')

%adds title to graph

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([-1000,1000,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 8: FM Signal without a carrier in the frequency

domain. No signals present because no carrier!

% Plot of Modulated Wave in Frequency Domain - Close

Up

freqPlot = figure; %gives graph window a name and

keeps it available

stem(SfRange,Sf); %Creates stem graph for magnitude

spectrum

title('FM Signal (No carrier) - Pos Spectrum

Closeup')

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

axis([0,1000,-.1,.4]); %defines axis

[x(min),x(max),y(min),y(max)]

Figure 9: FM Signal without a carrier in the frequency

domain (close-up). No signals present because no carrier!

Page 5: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 5

2. Part 2 – FM Modulation and Partial Demodulation in MATLAB

For the next phase of the lab a new square wave message signal is now generated in MATLAB using a VCO in Simulink. The message frequency and carrier were chosen in such a way as to be easily visible by the scope. The modulation and settings used in Simulink are illustrated by the figures below.

Figure 10: Simulink Block Diagram for FM Modulation

Figure 11: Simulink Pulse generator settings for

generating a 100Hz square wave.

Page 6: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 6

Figure 12: VCO settings for Modulating the input signal.

The quiescent frequency is the fc in FM and the Input

sensitivity is the kf in FM. Thus this should adequately

frequency modulate our message onto a 1k Hertz carrier

with a high enough Kf to produce around two to four

sidebands (wideband).

Figure 13: The output square wave in the time domain.

Figure 14: The output frequency modulated wave.

Figure 15: The message square wave in the time domain.

Notice a square wave has many low frequency components

(> 0dB.)

Page 7: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 7

Figure 16: The FM wave in the frequency domain. Notice

there are about four sidebands >0dB representing our FM

wave.

Now that we have produced a good modulated wave the next step is demodulation of the FM wave. The lab wished to demonstrate demodulation using a positive and negative slope detector simulated as transfer functions. However the next step following slope detection is envelope detection and an envelope detection module is not common to the Simulink library so this step could not be completed. Another approach to demodulation involved a phase-locked loop system, an easier process to manage in Simulink.

Figure 17: Partial Demodulation of FM wave using a

positive slope detector circuit in Simulink.

Figure 18: As a result of positive slope detection we

receive an FM-AM product. Using a good envelope

detector we could then attempt to demodulate our signal.

However a good envelope detector is a complex process

and requires several block sets in MATLAB. Another

approach is to use a phase-locked loop which was

demonstrated in another class project.

Figure 19: The AM-FM wave in the frequency spectrum.

3. Part 2 – Noise The next and final phase of the lab involved creating and plotting a noise signal in MATLAB in the time and frequency domain, as well as the autocorrelation function of that noise. This accomplished with the following code... % Noise signal

fs = 10000; %sampling frequency

ts = 1/fs; %sampling interval

t = 0:ts:1-ts; %time vector

nt = rand([1,10000]); % returns an n-by-n matrix

containing pseudorandom values

Page 8: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 8

% Plot of noise signal in Time Domain

timePlot = figure; %gives graph window a name and

keeps it available

plot (t,nt); %plots noise in time domain

title('Noise Signal - Time Domain'); %adds title to

graph

xlabel('Time (s)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

Figure 20: Noise signal in the time domain.

% Plot of noise signal in Frequency Domain

[Nf,NfRange] = centeredFFT(nt,fs); %Uses centeredFFT

function

freqPlot = figure; %gives graph window a name and

keeps it available

stem(NfRange,Nf); %Creates stem graph for magnitude

spectrum

title('Noise Signal - 2 Sided Spectrum') %adds title

to graph

xlabel('Freq (Hz)'); %adds xlabel to graph

ylabel('Amplitude'); %adds ylabel to graph

grid; %turns on grid

Figure 21: Noise signal in the frequency domain. Notice

noise is very small (almost 0) at higher frequencies but an

impulse at 0 Hz. This is as expected, which is why a small

resistor can do wonders at eliminating LF noise!

Now the autocorrelation function was found using the

following code...

% Plot of autocorrelation of n(t)

Rxx=xcorr(nt); % Estimate its autocorrelation

ACorrPlot = figure;

plot(Rxx); % Plot the autocorrelation

title('Autocorrelation Function of n(t)');

xlabel('time shift - lags');

ylabel('Autocorrelation');

grid; %turns on grid

Figure 22: Autocorrelation function of noise signal.

Finally Simulink was used to insert noise into a

sinusoidal message signal, a low pass filter was used to

eliminate the noise (while varying the noise). Lastly a square

Page 9: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 9

wave message was used and the output was again sent to the

slope detector circuit for analysis. The results follow..

Figure 23: Simulink circuit used for noise simulations.

Figure 24: This is a representation of the message signal

with large added Gaussian noise.

Figure 25: Message signal with large Gaussian noise after

LP filter, notice you can now kind of see the message.

Figure 26: Message signal with smaller amount of

Gaussian noise after a LP filter stage. Notice the noise is

much less now.

Page 10: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 10

Figure 27: Simulink block diagram used for Pulse

generator (square wave input).

Figure 28: Large amount of noise added to square wave.

If you can still call it that.

Figure 29: After LP filtering out the noise, where is our

signal? This is because a square wave contains many high

frequency components that just got filtered out!

Figure 30: Results of LP filtering our square wave with

less noise added to the signal. Now we are getting

somewhere, however we’ve still lost the form of our square

wave.

Page 11: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 11

Figure 31: Simulink block diagram used for simulating

noise entering an FM modulation scheme.

Figure 32: FM Scheme with added large noise. No longer

looks anything like FM!

IV. CONCLUSIONS

The frequency modulation (FM) process was easy to

simulate using MATLAB code. Beta’s influence in the

bandwidth of an FM signal was further reinforced, as well as

the concept of what drives frequency modulation (the

carrier). Without a carrier there is nothing to modulate thus

no FM signal.

The Simulink modeling of an FM wave further

improved my understanding and demonstrated that a slope

detector can be used to create an FM-AM hybrid wave that’s

AM potion can be envelope detected to retrieve a message

signal.

Graphing noise in MATLAB was a breeze and quite

informative. By simulating the noise in Simulink a greater

understanding of the drastic effects of noise on signals and

the important use of specially designed filters. It was finally

observed that noise plays an even greater role on digital

systems such as a square wave which contains several

frequency components. Isolating noise from such a system is

even more difficult due to the increased number of frequency

components (harmonics) making up the message.

This was a satisfying lab and if I had further time I

would have enjoyed fully demodulating the FM wave using an

additional negative slope detector and two envelope

detectors.

REFERENCES

[1] Haykin, S., “Analog and Digital Communications 2nd

Edition” John Wiley & Sons, Haboken, NJ, 2007.

Page 12: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 12

function Lab3 = Comm1Lab3() %Function name for calling in MATLAB % Colorado Technical University % EE 443 - Communications I % Lab 3 - MATLAB Project - Frequency Modulation/ Demodulation and Noise % By Loren K. Schwappach % Uses centeredFFT() for obtaining a two-sided spectrum

% --------------------------- % ------- TASK 1 % Generating Carrier, Message and Modulated wave Fc = 500; Ac = 2; Pc = 0; Fm = 25; Am = 1; Pm = 0; Beta = 0; fs = 5000; %sampling frequency ts = 1/fs; %sampling interval t = 0:ts:((1/Fm)*3); %time vector m = Am*sin(2*pi*Fm*t + Pm); %message wave c = Ac*sin(2*pi*Fc*t + Pc); %carrier wave st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM signal

% ------- B = .1 Beta = .1; st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM signal % Plot of FM signal in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t,st); %plots FM signal in time domain title('FM Signal (B=.1) - Time domain'); %adds title to graph xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,40e-3,-2,2]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of FM Signal in Frequency Domain [Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (B=.1) - 2 Sided Spectrum') %adds title to graph xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-800,800,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of Modulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (B=.1) - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([400,600,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% ------- B = 5 Beta = 5; st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM signal % Plot of FM signal in Time Domain timePlot = figure; %gives graph window a name and keeps it available

Page 13: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 13

plot (t,st); %plots FM signal in time domain title('FM Signal (B=5) - Time domain'); %adds title to graph xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,40e-3,-2,2]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of FM Signal in Frequency Domain [Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (B=5) - 2 Sided Spectrum') %adds title to graph xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-1000,1000,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of Modulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (B=5) - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([200,800,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% ------- FM Signal with No Carrier Beta = 1; Ac = 0; %Carrier is no longer transmitting st = Ac*sin(2*pi*Fc*t+Beta*sin(2*pi*Fm*t)); %FM signal % Plot of FM signal in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t,st); %plots FM signal in time domain title('FM Signal (No carrier) - Time domain'); %adds title to graph xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,40e-3,-2,2]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of FM Signal in Frequency Domain [Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (No carrier) - 2 Sided Spectrum') %adds title to graph xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-1000,1000,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% Plot of Modulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('FM Signal (No carrier) - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,1000,-.1,.4]); %defines axis [x(min),x(max),y(min),y(max)]

% ------- End of Task 1

Page 14: EE443 - Communications 1 - Lab 3 - Loren Schwappach.pdf

CTU: EE 443 – Communications 1: Lab 3: MATLAB Project – Frequency Modulation / Detection and Noise 14

% ---------------------------------------------

% ------- Task 2 is done with Simulink

% --------------------------------------------- % ------- TASK 3 % Noise signal fs = 10000; %sampling frequency ts = 1/fs; %sampling interval t = 0:ts:1-ts; %time vector nt = rand([1,10000]); % returns an n-by-n matrix containing pseudorandom values

% Plot of noise signal in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t,nt); %plots noise in time domain title('Noise Signal - Time Domain'); %adds title to graph xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid

% Plot of noise signal in Frequency Domain [Nf,NfRange] = centeredFFT(nt,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(NfRange,Nf); %Creates stem graph for magnitude spectrum title('Noise Signal - 2 Sided Spectrum') %adds title to graph xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid

% Plot of autocorrelation of n(t) Rxx=xcorr(nt); % Estimate its autocorrelation ACorrPlot = figure; plot(Rxx); % Plot the autocorrelation title('Autocorrelation Function of n(t)'); xlabel('time shift - lags'); ylabel('Autocorrelation'); grid; %turns on grid

% ------- End of Task 3 MATLAB code portion % ---------------------------------------------

% end Comm1Lab3