You are on page 1of 163

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/277871349

Amplitude/Frequency Modulation Matlab GUI Project

Conference Paper · June 2015

CITATIONS READS

0 6,535

1 author:

Hj Lee
Korea University
2 PUBLICATIONS   0 CITATIONS   

SEE PROFILE

All content following this page was uploaded by Hj Lee on 08 June 2015.

The user has requested enhancement of the downloaded file.


Amplitude/Frequency Modulation
Communication System

Matlab GUI Project

Final Report

EIEN405- Electronics Engineering Design

By

Hong Ju LEE

June 2015

1
Abstract
This Matlab GUI design were implemented to help out students to comprehend
amplitude and frequency modulation easily. This model includes Double Side,
Single Side, Vestigial Side Band, Frequency Modulation, FM threshold effect
simulation and Superheterodyne Receiver. Most of them would be run on the
Matlab Graphical User Interface format released in 2014a version. Each of design
supports fundamental modules to proceed the modulation and demodulation.
The GUI models and designed m.files were consisted of fig file and m.file.

2
Table of Contents
1 Introduction
Double Side Band Modulation
2 Background
(Page 4)
3 Design/Implementation
1 Introduction
Single Side Band Modulation
2 Background
(Page 14)
3 Design/Implementation
1 Introduction
Superheterodyne Receiver
(Page 19) 2 Background
3 Design/Implementation
1 Introduction
Vestigial Side Band Modulation
(Page 28) 2 Background
3 Design/Implementation
4 AM conclusion
1 Introduction
Frequency Modulation
(Page 35) 2 Background
3 Design/Implementation
4 FM threshold effect
5 Pre/De emphasis
6 Conclusion
Matlab File List Envelope
Appendix A
Detector,Power

Function List
Appendix B

Code File
Appendix C

References

3
Double Side Band Suppressed

Carrier Modulation

4
Chapter 1 Introduction

This model is designed to demonstrate double side band suppressed carrier modulation
of human voice signal. And it is the first version of Matlab Graphical User Interface (GUI)
model, so it supports simple and basic modulation and demodulation part. The further UI
model series will show more functions and systems to help students to understand analog
communication theory.

This GUI file has 5 sub window: Load File, Pre-Filtering, Modulation, Demodulation and
White Noise part. Each of system will be explained in chapter 3. In case of loading the
voice signal, I stored 8 different my voice and radio signal under different sampling
frequency. The sampling frequency of the wave files (Sample_Voice_1~4) is 8000 Hz and
the sampling frequency of the wave files (Sampling_30KHz_1~4) is 30 KHz. The reason why
I recorded different sampling frequency will be explained in the chapter 3-1 and discussed
in other GUI design (Superheterodyne receiver part).

<The DSB-SC GUI model>

5
Chapter 2 Background

1. Filter Design (firpmord function case / designfilt case)

At the each of GUI file and m.file, the filter design is necessary to demodulate the
modulated signal, reduce the noise power or to get the only wanted signal from multiple
sources. I used the Parks-McClellan optimal FIR filter order estimation method to design
low pass, band pass, band stop, and high pass filter. The Matlab ‘firpmord’ built in function
supports this algorithm and I coded filter functions to call the ‘firpmord’ to build proper
filters. It will design minimum order of filter each time when the function is called; however,
it takes much time to calculate the process, so it will take 3 or 5 seconds to filter the
signal in GUI design.

Another filter design method is using ‘designfilt’ function in the Matlab. It supports FIR
and IIR filter design. Also, in some case of filter design, the order could be fixed and the
pass and stop band are designer’s choices. I used this method in the FM design because
it took less time to filter signals.

2. Filter function ( required Signal Processing Toolbox )

To filter signals, I used ‘filter’ function to get the output signal through designed filter
from input signal. The filter function is based on the direct form 2 transposed structure.
The below figure is from the help window in the Matlab. I implanted ‘filter (designed filter,
1, input signal)’ format to derive the output signal.

The filter’s group delay will occur and delay the signal in time domain. This GUI is simple
design, so I did not consider the influence of filter group delay. But in the FM design, I
used different function to compensate the delay problem. It will be explained in the FM
design.

6
3. wavread function warning message

I used ‘wavread’ function to read recorded voice signal. When the fig file is executed and
load wave files, the following message will be shown in the command window. Before
planning GUI file, I already used this function to record and check the wave file in other m
file. So I have kept this function design in series of designed GUI files.

7
Chapter 3 Design and Implementation

1. Load File Button/Play Button

This button takes only wave format of voice signal. The voice signal file should be in the
same folder with this m.file. This m.file did not include how to record the voice signal, so
I explained how to record the voice by using Matlab.

At first, make another m.file to record your voice signal. Following code will help you to
start the code. In the below figure, ‘fs’ means the sampling frequency of record and it
decide your frequency domain and quality of samples. The maximum frequency would be
half of the sampling frequency. It could be checked in the UI figure. Thus, if the fs is below
6000Hz, it will limit the frequency domain in the GUI figure and the range of carrier
frequency. It is recommended to set over 20 KHz to record the voice allowing more capacity
for the carrier frequency. ‘Bits’ represents the bit level to record the voice signal. Matlab
supports 16 and 32 bits to record sounds. I set 16 bits to lower amount of input data to
reduce simulation time. ‘Audiorecoder’ and ‘recordblocking’ are Matlab built-in function to
support recording and store the recording data.

After recording the voice signal, the load and play button loads the recorded wave file
and play the chosen file sound.

<Record the voice and load file>

8
2. Pre-Filtering Button (Low pass filter)

The reason I designed this low pass filter is that I wanted to minimize the bandwidth of
the original signal. So, it allows me to set the carrier frequency is lower than I expected
and to plot the modulated signal on the frequency domain. As you can see the frequency
domain range, it was determined by the sampling frequency, which was already decided
to record the sample voice signal. Within this range, it would be difficult to see the
modulated signal frequency spectrum (Assuming the carrier frequency is much larger than
the bandwidth of the modulating signal.). Thus, I wanted to cut some high frequency term
and low the carrier frequency representing modulated signal on the same plot figure. As
you see the spectrum image, the most of frequency spectrum components is located at
the low frequency while few of them is at high frequency (over 2000Hz); however, cutoff
high frequency components would be degrading the original voice sound.

The reason is because each of certain vowels has their frequency characteristics. It will
explain why the low pass filter degrades the original voice. I appended an image from
other source [ 1 ] to explain the voice frequency
characteristics. Each of a letter frequency represents
their own frequency spectrum even if the power of
them (amplitude of FFT) is much less than others.
Therefore, if you apply this pre filter to original
sound, it could be hard to detect the voice sound
(unclear and blur sound). Thus, just use this low pass
filter to understand how the modulated signal
spectrum would be plotted. If you want to just pass this part, just set the cutoff frequency
as 3969Hz. Otherwise, set the cutoff as lower than 2000Hz.

① Korean J Otorhinolaryngology-Head Neck Surg 2008;51:1099-103, DOI 10.3342/kjorl-


hns.2008.51.12.1099

9
<The Pre Filtering Effect>

10
3. Modulated Signal 1

This window is the amplitude modulation part. The blank window is the carrier frequency
input to modulate the voice signal. The unit is Hz, and due to the sampling frequency
please be aware of setting the carrier frequency. I attached 3 different results to show

which one is right and wrong simulation.

In the first case, carrier fc is 2000 Hz and its frequency spectrum is identical with the
result of double side band amplitude modulation. But, in the second case, carrier fc is over
the maximum frequency and the frequency spectrum is not what it is expected. Since the
fft is circular calculation, the spectrum is overlapped and plotted like the image.

In the reality, the carrier frequency is much larger than bandwidth of the message signal;
however, this UI only shows limited frequency range from -4000 to 4000(when fs is 8000Hz).
If you want to modulate the message signal over the range, record the sample voice at
higher frequency. For this reason, in the record file, I added 30 KHz sampled signals.

11
4. A (synchronous demodulation)

This window is the part of demodulation. It is required two inputs-carrier frequency and
phasor error. This is basic demo version, so it did not consider phasor delay due to the
distance between transmitter and receiver. So, the receiver performs the demodulation
under the different carrier frequency and phasor condition. If the carrier is not same with
one at the modulation, the demodulate signal would be undermined and tolerated. Also,
the phasor error affects the quality of demodulated signal. But its influence is not much
critical than carrier error.

(When the demodulation carrier is not same with modulation carrier)

(When the phasor error is 30°)

12
5. White Noise

This interface adds additive white Gaussian noise signal to amplitude modulated signal.
In this window, the input blank (‘Amplitude of Noise’) means the multiplying value to the
random signal. Its expression is not correct, but I called it the amplitude of noise in here.
If the value is changed, the noise power and signal to noise ratio (SNR) will be changed.
The part of this code will help you to understand what the value is referred to.

The ‘Noise’ variable is referred to input number of the GUI blank. And it multiplies randn
function to output white noise signal. Through several attempts to get the proper noise
power, it is recommended to set the input value is below 0.5 point.

In the code, I generated white noise using randn Matlab built-in function. The detail of
how to generate noise signal will be detailed in the FM design.

The left image shows how it works


properly. If the noise value is determined,
please push ‘Add White Noise’ button to
add the noise to modulated signal. Since
this callback function was designed to
take the modulated signal, the
modulation part must be proceeded in
advance.

The SNR button shows the SNR value in dB unit. I used ‘snr’ Matlab built-in function in
this design. In the next design, I used ‘spower’ designed function to calculate SNR value.
Other buttons (Demodulation and Play) will demodulate noisy input signal and play the
demodulated voice sound. When the signal is demodulated, the demodulation carrier
frequency is set as same with one in modulation (no frequency and phasor error).

13
Single Side Band Suppressed

Carrier Modulation

14
Chapter 1 Introduction

This user interface supports single side band modulation and demodulation to help
students to understand how the voice signal would be modulated graphically. The design
consists with 5 step: load File, low-pass Filtering, band-pass method design, phase shift
design and coherent detection. The main goal of this design is to compare the two different
modulation methods and check the each of modulated signal is identical.

15
Chapter 2 Design and Implementation

1. Load File and Pre-Filtering (same design with DSB design)

In the sampling folder, the user could choose two different sampling voice signal-one is
sampled by 8 kHz and the other is sampled by 30 kHz. The first option allows user to
easily see how the frequency spectrum would be plotted. On the other hand, the second
one has more sample points to plot the spectrum within the same figure window. Thus, it
is recommended to load 8 kHz voice file to check the spectrum easily.

2. Band pass filter method

I designed two different method to generate single side band modulated signal. The first
one is filtering method to pass upper or lower side band of modulated signal. The SSB
modulator figure [ 1] will help to understand the output spectrum.

In the UI, the user can decide upper or


lower sideband of the modulated signal.
The following capture is when the upper
band is chosen.

1
Communication Theory Chapter 3 page 111 figure(1)

16
3. Phase shift method

The second design to generate single side band modulated signal is to use Hilbert
transform, known as phase shift method. The below figure [ 2] shows the entire process of
phase shift design. This design required Hilbert transform of message signal m(t). So, I
used ‘hilbert’ Matlab built in function to execute the hilbert transform. The result of hilbert
function is complex value including real and imaginary parts of the signal. Therefore, I took
imag function to get only imaginary part and calculated the balance modulator without
warning message. If you erase the imag function in my design, the SSB output would be
complex signal and frequency spectrum would not be even symmetry.

In the both design, when the carrier


frequency is 2000Hz, frequency spectrum is
identical in the both filtering and phase shift
method except the scaling factor.

2
Communication Theory Chapter 3 page 113

17
4. Coherent detection

To demodulate the single side band modulated signal, I designed coherent detector to
recover the original signal. Since SSB modulation has been developed in two different
methods, I added popup menu to select which one is the modulation option. In the panel,
3 input values (Carrier Fre, Amplitude of Noise and Phasor error) are required to proceed
this demodulation design. ‘Carrier Fre’ means demodulation signal frequency, and the
phasor error is the phasor components of the cosine demodulation signal. ‘Amplitude of
Noise’ refers the deviation of random signal (randn) to change the white noise power.

If the 3 input are set, please press the


‘Add White Noise’ button to generate the
white noise signal to the demodulating
signal. In case of ideal transmission
without additive white noise, the number
0 must be determined in the ‘Amplitude
of Noise’ blank.

Below this button, ‘SNR’ button executes SNR calculation in dB scale. The simulation time
is limited 5 seconds (the voice recording time), and the white noise could not be generated
in constant power spectral density by frequency domain. The detail of white noise part will
be handled in the FM SNR model. Other buttons (Demodulation and Play) will demodulate
the demodulating signal using the input information and play the output signal.

<GUI after the demodulation>

18
Super Heterodyne Receiver

19
Chapter 1 Introduction

This GUI model demonstrates how Superheterodyne receiver works. The main interest of
this design is to understand the role of intermediate frequency and local oscillator. To avoid
difficulties to design tunable band pass filter to get wanted signal source from multiple
signals, the Superheterodyne receiver has been devised. I designed 5 sub panels following
each step of the receiver structure. In this design, the textbook [ 1] and some pdf files [ 2]
helped me to simulated this receiver model. In the chapter 3, the detail of the design will
be discussed.

<The GUI file design>

1
Introduction to Analog and Digital Communication written by Moher

2
EE 160 pdf, Spring 2010 San Jose State University

20
Chapter 2 Background

The above figure is the entire part of Superheterodyne receiver. RF amp and Channel filter
refer the RF section, and IF amp and IF filter refer the mixer section. The last part
demodulator is demodulation of the signal.

<The Frequency Spectrum> 3

The figure 3 explains how the image channel is shifted to intermediate frequency. Instead
of varying carrier frequency to demodulate different spectrums every time, the
superhetodyne receiver executes the demodulation changing the intermediate frequency.

3
Page 3, EE 160 pdf, Spring 2010 San Jose State University

21
Chapter 3 Design and Implementation

1. Load Multiple Voice files

This model was designed to get selected signal from multiple signal sources, so in this
panel, it supports the 4 different load wave file and play buttons. If the wave file is loaded,
the play button can be used to check whether the file is successively loaded or not. The
‘Help’ button at the top of the panel explains the voices signal information – bandwidth
and sampling. This is essential
information to decide the carrier
frequency to double side band
amplitude modulate in the second
panel.

Due to the limitation of frequency


domain, I did not plot the spectrum
of each signal in this design.
Therefore, the 30 KHz sampled voice
signals are recommended in the view of the quality of voice. In the help message, I limited
the bandwidth as 5000 Hz to lower the carrier fc; however, if the user want to set the
carrier fc is much larger than half of the sampling frequency, it does not bother any further
simulations.

2. Double Side Band Modulation

This panel has 4 modulation buttons and blank windows to modulate the input signal.
The number of each sub panel matches the input voice sample number. In the code, I set
the minimum carrier fc as 15000 Hz (half of the sampling frequency) and if the input fc is
lower than the 15000, the error message will be shown. The reason why I designed like
this is to simulate this model in more reality environments (In the previous models, the
carrier fc has not been over the sampling frequency).

As it executes double side band modulation, the modulated signal has double bandwidth
of the original signal. This model did not support any options to differentiate the
overlapping different frequency spectrums, so please be careful to set the 4 different carrier

22
frequencies. The carrier frequency deviation between two adjacent carriers should be larger
than at least 10 KHz. If the user wants exactly correct demodulation result in the final stage,
the interval would be larger than the sampling frequency (30 KHz). I simulated this model
when the interval was 20 KHz. The following figures are error message window and success
message window when the carrier fc is determined in the correct range or out of the range.

<Setting the Carrier Frequency>

The below capture image is an example to decide the 4 different fc. See the carrier interval
is 20 KHz to modulate without interfering other signals.

23
3. RF section

In the real system, band pass filter to filter the wanted frequency band in the frequency
domain. The role of the RF section is the blue window in the following figure (Channel
filter). In this design, the 4 different modulated signals are the only considering spectrum,
so I just made the ‘filtering’ button to show the step of the entire process.

<Frequency Spectrum in the receiver>

24
4. Mixer

In the Mixer section, the popup menu would be chosen first, and the intermediate
frequency (fIF) is the second required input. The intermediate frequency decides local
oscillator frequency (fL). If the fIF is lower than 5000 Hz, error message will be shown since
the fIF is lower than the original voice signal spectrum.

<Mixer Output Spectrum> 4

The IF filter in the figure is not designed in the model. Instead of adding filter, the popup
menu selective option takes only the desired channel. The selected signal would be the
input of the next step (‘Coherent Detection’).

4
Page 4, EE 160 pdf, Spring 2010 San Jose State University

25
Local oscillator frequency (FLO) = Carrier frequency (Fc) + Intermediate frequency (FIF)

This is relationship between FLO and FLF. In the GUI design, the selected one from popup
menu decides which carrier frequency (Fc), and then FIF input is written down correctly,
the mixer button will represent the FLO in the UI window. The local frequency was
designed to multiple with the modulated signal. And the frequency spectrum result is well
shown in the figure of 3.RF section.

The above image shows the logical local oscillator


frequency (20000 + 6000 = 26 KHZ). The left side image is
the part of code to find each of fc value and calculate the
local frequency.

26
5. Coherent Detection

In the final stage, signal after the RF section is not baseband signal. It is required to
demodulate the signal using coherent or non-coherent detection (envelope detection). In
the communication theory print 5 , envelope detector is implemented to get original
message signal. The envelope detector is more convenient and cheaper detection than
coherent detection; however, the main goal of this model is to check the demodulated
signal and compare it with original voice sample. So I designed coherent detector to filter
only baseband spectrum.

After the RF section, the signal spectrum is centered at intermediate frequency. To get
the baseband spectrum, the same intermediate frequency should be multiplied with the
RF section output. In the panel, the ‘Demodulation Frequency’ input must be same with
intermediate frequency, which was just determined in the previous panel. This model is to
help students to understand the each step of the Superheterodyne receiver, so I made the
demodulation frequency in blank to remind students of the each demodulation step.

The other blanks are phasor error in the demodulation signal and amplifier gain of the
original signal. The phasor error has been explained in the previous GUI model, so I did
not repeat this part here. The Gain blank is the amplitude of the demodulation signal. The
following code shows how these variables are designed. After this design, low pass filter
passes only the baseband signal and plots the final signal spectrum.

5
Page 126, chapter 3.7 Superheterodyne receiver in the Communication Theory print context

27
Vestigial Side Band

Modulation

28
Chapter 1 Introduction

This model includes vestigial side band modulation process which allows students to
understand how the shaped spectrum through vestigial side band filter could be
demodulated. The input of the filter is a voice sample and the shaping filter and low pass
filter at the receiver are designed ideally. It means that the filter’s pass and stop band are
set in frequency domain just like drawing a line graph.

In this design, to reduce simulation time and amount of processed data, only positive
frequency part was taken and preformed. In the last part of the design, the positive part
was copied to fill in the negative side and completed the entire signal spectrum.

Plus, the modulation and demodulation process are executed in frequency domain, not
in time domain. In the frequency domain, all calculation is convolution, so this design is
implemented in different method to derive expected results. The detail will be handles in
chapter 3.

1
This above figure demonstrates VSD modulation/demodulation. Following this
algorithms, the shaping filter and coherent demodulator were implemented.

1
Page 45, Chapter 3, Communication Theory Print PDF

29
Chapter 2 Background

The advantage of vestigial side band modulation is to design a single side band pass filter
more easily. In case of designing SSB filter to filter a desired signal from multiple signal
spectrum, the sharp cutoff at the stop band frequency is required; however, the VSB filter
eliminates the sharp cutoff property and makes the filter design more conveniently. The
following filter spectrum shows the filter property between upper single side band pass
filter and vestigial side band filter 2.

This model was designed to take upper sider band of the signal. The main focus of this
design is to set the stop band of the signal (fc-f1) and the half power of the signal at the
fc. The upper stop band of the VSB filter is not main interest.

2
Page 8, Lecture #11, Vestigial Side Band Modulation KEEE 343 Communication Theory pdf

30
Chapter 3 Design and Implementation

1. Ideal Shaping Filter Design

The double side band modulated signal is the input of the shaping filter. I set the carrier
frequency as 5 KHz and the stop band as 2 KHz considering the double side band is about
10 KHz. So, the lower stop band is 3 KHz, and pass band is 7 KHz. The higher stop band
is set 10 KHz. The below figure is the filter characteristics. At the 5 KHz, which is the carrier
frequency, the magnitude is located at the half (0.5) and the red colored area should be
same. To satisfy the condition, I designed linear shaping filter.

31
2. The Shaping Filter Result

These two spectrums are the output through the VSB filter. The left side one shows the
positive frequency part and compares the original spectrum and shaped spectrum. The
right side one is expended spectrum to both frequency part. I used ‘fliplr’ Matlab built-in
function to mirror the frequency image.

3. Coherent Demodulation

After the shaping filter, the signal would be transmitted and demodulated by the coherent
demodulator. In this design, I used convolution function to execute multiply in time domain.
In the Matlab, the ‘conv’ function supports the same length output result with the input
signal length. ‘conv(x, y, 'same')’ is the code I have implemented to fit the frequency domain
after the convolution. The below result is the output of the demodulation. The side
spectrum will be canceled by the low pass filter.

32
4. Ideal Low pass filter

The side band spectrum is canceled and the baseband signal is only taken. I set the
bandwidth of the original signal as 5 kHz, and the bandwidth of the low pass filter is same
bandwidth (5 KHz). The Shaping filter was designed ideally, so to meet the calculation in
frequency domain, the low pass filter was also implemented ideally. The property of the
low pass filter is the exact rectangular pulse form.

The following result is the demodulation frequency spectrum. Due to the filtering, the
scale of the spectrum has been decreased. And the convolution calculation does not derive
exact values compared to the fft result of the original signal. Since I cut off the bandwidth
of voice sample is 5 KHz, the side band (over 5 KHz) did not include in the convolution
and filtering. I believed that the side band value might affect the demodulation result.

33
Chapter 4 AM Conclusion

The Amplitude GUI and m.file designs include Double Side, Single Side, Vestigial Side
Band Modulation and Superheterodyne Receiver. Each model supports voice sample as
input signal. These four designs were made to how the voice signal was implemented with
amplitude modulation theory. In the textbook, most of problems and examples takes only
sinusoidal or determined signals to calculate easily. I hope this design helps students to
comprehend how the frequency spectrum is shifted through Amplitude Modulation and
Demodulation.

In 4 different designs, I could not increase the carrier frequency fc much larger than the
message bandwidth when the input signal is voice sample due to the limitation of the
sampling frequency and size of plot figure. These communication models were based on
the analog modulation, so the message signal itself had the continuous waveform which
would be filtered and calculated one by one. Plus, error detection and correction caused
by the Gaussian White Noise could not be handled in this model. In the future, these
communication models will be improved and implemented by digital modulation including
source encoding and channel coding part.

In conclusion, these four Matlab files assist students to simulate the analog amplitude
simulation and provides its graphical results.

34
Frequency Modulation/Demodulation

And FM Threshold Effect

35
Chapter 1 Introduction

This Matlab Graphical User Interface (GUI) and Matlab m.file was designed to
demonstrate how the single tone or multiple tone signals would be frequency modulated
and demodulated. Basically, the following codes and systems are based on the
‘Introduction to Analog and Digital Communication’ written by Haykin and Moher.

I designed several systems, such as direct FM generator, hard limiter, band pass filter,
differentiator, envelope detector, and low pass filter to check the final output signal is
identical with the input signal. Plus, I added power spectral density (PSD) result figures
after the systems and FM threshold effect result. To achieve both simulations efficiently, I
separated each simulation to reduce the simulation time and to show the spectrum image
directly. The first design model is ‘Armstrong.fig’ GUI file to show the spectrum of signals
through the FM modulation/demodulation algorithms and the other design is
‘simulation.m’ file to show the FM threshold effect and PSD.

The GUI file’s goal is to show how the input signal’s time and frequency spectrum would
be plotted through each step of frequency modulation and demodulation. It took so much
time to simulate if the time sequence of the input signal is over 1000 seconds, so I limited
the length of simulation time of the GUI design. It might not satisfy the constant power
spectral density of the additive white Gaussian noise part of the design; however, the main
interest of the GUI design is not to simulate FM threshold effect.

To compensate the limitation of the previous design, two ‘simulation.m’ files simulate
only FM Threshold effect and check the power spectral density of each signal. One of the
m.file shows the FM threshold effect without pre and de-emphasizing. And the other one
represents how the pre and de-emphasizing filters enhance the FM threshold effect. I set
the length of time as 5000 seconds to show the result. The detail of simulation time will
be discussed in the Chapter2-3.

36
Chapter 2 Background

1. Wideband FM Bandwidth Analysis

In the popup menu of my GUI model, the first option is single cosine input, and the
second and third option are 2 cosine signal and level signal. To design band pass filter at
the demodulation part, the bandwidths of multiple cosine signal and level signal are
necessary.

In the first case, the bandwidth of the signal was estimated by Carson’s rule using the
first kind of Bessel function. Tone-modulated FM wave has infinite number of sidebands;
however, the required transmission bandwidth has 98% of FM signal power in the
bandwidth applying Carson’s rule. 1

In other cases (not single-tone input), I used the fallacy described in other book 2. The
conclusion of the bandwidth of these signals are also estimated by the Carson’s rule. The
only difference in the formula is peak frequency deviation ∆f. In the case of single tone,
∆f is Kf*Am, and in other cases, ∆f is Kf*(amplitude from source 1 +amplitude from source
2).

1
Page 146, Chapter 4, Communication Theory PDF

2
Page 216, Modern Digital And Analog Communication System 4th edition written by B.P. Lathi

37
2. Additive Gaussian White Noise

In the Matlab, Gaussian White Noise could be generated by two methods. One is ‘wgn’
built-in Matlab function and the other is ‘randn’ function. Both of them executes almost
same noise signal. Only difference is that the wgn supports the load impedance value
(default is 1). So, I plot power spectral density of both noise signals to compare how the
load impedance affects the power. (Under such conditions: time sequence 5000 sec,
sampling time is 0.005 sec, and using pwelch to estimate PSD).

Plus, these PSD plot results are consistent with the ‘White’ Gaussian Noise power spectral
density property only when the simulation time sequence is large enough to estimate
nearly consistent power over frequency domain. If the simulation time is lower than 5000
sec, such as 1000 or 2000 sec, the PSD would be more fluctuated.

One of the assumptions of the FM-SNR analysis is the noise power spectral is always
considered as constant value. To satisfy the assumption, it is required to extend the
simulation time; however, as the simulation time is increased, the calculation data is also
increased. Thus, it will takes more times to get the result of the input signal. This is trade-
off between time simulation and noise power spectral density.

38
Chapter 3 Design and Implementation

1. Original Signal (sinusoidal signal / Multiple Signal)

The first option in the popup menu at the ‘load file’ window demonstrates how the input
cosine signal would be modulated and demodulated following each step of the Frequency
Modulation process.

The sinusoidal signal (so called message signal) is Am*cos (2*pi*fm*t) form, which means
Am is the amplitude of the signal, fm is the message frequency and the t is the time vector.
The time duration and sampling frequency have already been determined as 50 seconds
and 2000Hz, so the only parameters the users should set are Am and fm. To avoid error in
the filter design (filtfilt problem-explaining in the 5th step), fm must be larger than 30Hz.
After setting those values, push the ‘load file’ button to see the time domain signal and
frequency spectrum.

It would be hard to check the time domain form of the original message signal since the
time period is 1000 seconds; however it is required to extend simulation time sequence to
derive nearly constant power spectral density of White Gaussian Noise.

The original signal generation (Am=1, fm = 40 Hz)

39
2. Direct FM Method and Parameters Check-Point

The second window is to modulate the message signal by direct method (VCO). Before
designing this UI, I had designed the FM signal following the Armstrong indirect method
to generate wide band from narrow band to perform frequency modulation; however, it
was not catchy to see the bandwidth’s deviation between the narrow band and the wide
band signal due to the small plot figure in UI. Although the direct method causes instability
of the FM signal, it does not affect the output of the signal and the main goal of this
design.

The Parameter check point shows basic parameters, such as Kf, delta f, Beta and Bandwidth
of the FM signal. To calculate the bandwidth, I applied Carson’s rule.

<Result of Direct FM Generation (Fc = 500, Kf =10)>

40
3. White Gaussian Noise

The third window is to add White Gaussian Noise to FM-signal. The Noise Power in the
window means that the amplitude of noise signal. I generated the white noise importing
built-in function-wgn-in the Matlab. The help (F1) in the Matlab will explain the detail
process to generate the noise.

At this point, I defined 3 different signal name: total_signal, white_noise and only_signal.
The reason I separate the FM signal and noise is to make it easy to simulate threshold
effect in the end of the simulation. Thus, each of the procedure is same as others. To avoid
ambiguousness of each signal, I refer the total signal as the summation of FM-signal and
the noise.

The ‘generate’ button will show not only the total signal’s time and frequency spectrum
but also each of signal’s power spectral density. I used ‘pwelch’ built-in Matlab function to
estimate power spectral density with frequency (Hz) domain.

4. Hard Limiter

The next window is to limit the amplitude of the total signal. The hard limiter cuts the
amplitude over 0.5. In the textbook, the limited amplitude is 1; however, the time domain
signal below fluctuates over value 1.

The main interest of the signal is not the amplitude of the signal, but the zero-crossing
rate. It shows how the signal carries information. So, I set the limitation as 0.5 in this design.

41
5. Band-Pass Filter

The 5th window passes only the bandwidth of the total signal by applying the Carson’s
rule. In the band-pass filter design, I set the passband as 99% of the stopband and
stopband as exactly the same of the half of the Carson’s bandwidth from the carrier fc. The
following figure is the filter visualization through the Matlab fvtool. (When fc = 500Hz,
Bandwidth = 60, fs = 2000Hz)

<Filter Information and its visualization>

The filter is not ideal band-pass filter, so the passband is not a rectangular form which
is applied in the text book to demodulate the FM-signal. If I increase the order of the filter
over 50(the current setting value), the filter would be more like ideal band-pass filter (not
exactly). In spite of designing ideal like filter, I limited the order of the filter due to the
group delay of the filtering. The delay of the filter is also coincident with the reason why I
used the different function to filter the signal. In this design, I used ‘filtfilt’ built-in Matlab
function to convolution and filter the signal rather than ‘filter’ function. The ‘filtfilt’ function
performs zero-phase digital filtering which allows signals are being processed without filter
delay. On the other hand, this function requires additional condition-the length of the
input must be more than three times the filter order. The further explanation would be
explained in the ‘help’ Matlab. The bottom line is that I could not increase the filter order
to get ideal signal result described in the text book.

42
The figure below shows how the group delay of the filter affects the output signal and
degrades the FM-demodulation performance.

<Filter group delay and its influence>

<After the Band pass filter>

43
6. Phasor Detector (with differentiator)

The next step is to get the envelope of the signal or the phasor component of the signal.
I used ‘ev_phas’ function to calculate the input signal’s envelope and phasor term. The
function part will be explained in the appendix. At first, I derived the phasor of the total
(FM_signal+noise) not the envelope term. The main interest of the project is to demodulate
the FM signal not considering how to design the hardware satisfying each step of the
software design. Therefore, I wanted to avoid removing dc of the signal after the envelope
detector. The phasor information carries the original message signal with scaling 2*pi*kf
term when the signal has no additive Gaussian white noise. It requires only scale down the
2*pi*kf value to get the message signal.

44
7. Low pass Filter

The low pass filter limit the power of the noise to increase SNR value. Thus, the signal
would not be affected by this low pass filter. Only the noise signal would be cut off at the
stopband of the filter. I defined the stop band as the same frequency of the original
message bandwidth. The following is filter visualization when fm is 100 Hz.

<After the Low pass filter>

45
8. Threshold Effect (simulation.m file)

This button shows the threshold effect of FM. At first, I wanted to show the effect using
the noise power and the signal in the previous window; however, it took so much time to
repeat the simulation to plot the effect graph. Thus, I made another simulation.m file to
plot only the effect simulation. If the simulation button is activated, it will show just the
multiple FM threshold effect figures under different conditions (Am and kf values). If user
want to change the basic variables, such as Am, fc, fm and kf value, it is recommended to
rewrite those value in the m.file script. In the case of setting values, please be aware of the
limitation due to the band pass and low pass filter’s stop and pass band frequency. If the
Am is above 4, some errors will occur since the band pass filter cannot be designed (The
magnitude of bandwidth is larger than center frequency). If the user want to simulate over
4 Am, please change the carrier frequency to satisfy the filter design condition. I fixed the
carrier frequency fc and message frequency fm when running this model.

At first, I tried to achieve non-linear FM threshold effect result using same design in the
GUI file; however, since I wanted to analysis both signal and noise terms together at this
time. The designed model in the GUI could not execute the noise power spectral density
at the final stage. So, I changed the model to fit SNR analysis and PSD. The detail will be
continued in Chapter 4.

46
Chapter 4 FM Threshold Effect (Umemphsized.m file)

1. Simulation Environment

I fixed carrier frequency of frequency modulation as 500Hz


and length of simulation time as 5000 seconds. The below
figure is the code for initializing the variable to start the
simulation. I appended my simulation results to explain how
the threshold point is located and the influence of modulation
index (Beta) to threshold effect.

𝑘𝑘𝑘𝑘𝑘𝑘𝑘𝑘
The modulation Index (Beta) = (𝑘𝑘𝑘𝑘: 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠)
𝑓𝑓𝑓𝑓

I simulated this model changing the message amplitude Am and Kf value to derive the
effect of Beta on the FM threshold effect. I believed the Am variable is convenient way to
vary the beta rather than other variables since I tried to increase kf or fm, they will affect
the bandwidth of FM signal and occurs some errors in band pass filter design.

In each simulation, the randn function’s amplitude variable ‘Amp’ is set to be decreased
until the ‘Amp’ is small enough to show non-linear SNR graph while the signal power is
fixed. To hold on all pre/post SNR values, scatter function is used to plot the FM threshold
effect graph. The threshold effect simulation results are attached in the ‘chapter 5’ to
compare the pre/de-emphasis filter effects.

47
Chapter 5. Pre / De-emphasized Simulation (Emphasized_Simulation.m file)

1. Simulation Environment

In the second simulation, the pre and de-emphasized filters have been added to reduce
noise power at the high frequency range. The high frequency range refers the frequency
near the message bandwidth fm.

The simulation is executed when the input message signal is single tone cosine signal.
So, the message bandwidth is narrowed (mathematically delta function form). Due to the
narrowed bandwidth, the effect of the pre emphasized filter is not performed effectively;
however, I tried to find balanced emphasize and de-emphasized dB value between filters
to offset each effect.

This design shows how the filters affect the FM threshold effect and compares the SNR
graphs. I simulated 4 different parameters (kf and Am) to compare the previous SNR graph.
Other values, such as fc, fm, and fs, are same with the previous simulation file. Since the
fm is 100Hz in all simulation case, the main interest of the filters is the dB scale near the
fm. The detail design of pre and de-emphasized filters will be discussed in the next page.

48
2. Pre-emphasized Filter Design

1
The design of the pre and de-emphasized filter are ideally designed the below one.

The low frequency of the pre-emphasis curve keeps the 0 dB scale, and the emphasized
dB scale increases linearly. At first, I tried to design high pass filter to design like this figure;
however, the constant and linear dB scale were not easy to be implemented in the filter
design tool (fdatool and designfilt function). So, I set the first order pole and zero transfer
function to design the pre-emphasized filter. The following code shows the transfer
function and its frequency spectrum. The ‘fvtool’ function shows the filter’s characteristics.
In the frequency spectrum figure, the dB scale is not 0 dB and the spectrum form is not
linearly increased form. If the filter is implemented with exact and multiple pole and zeros,
the filter would be designed like the reference image. Since the low frequency range is
also emphasized, the de-emphasized filter should be designed to offset this characteristics.

1
DAE notes, (Pre and De-emphasized filter introduction)

49
<Pre-emphasis Filter Characteristics>

50
3. De-emphasized Filter Design

This curve is de-emphasized filter frequency spectrum and is identical to low pass filter
spectrum, which has the stop band at fm Hz. To balance the pre-emphasis curve, I designed
IIR low pass filter and lower the filter order to offset the pre-emphasized magnitude. The
below figure represents the pre/de-emphasis response. 2

2
DAE notes, (Pre and De-emphasized filter introduction)

51
<De-emphasized Filter Characteristics>

52
At the 100 Hz (fm), the dB scale of the pre-emphasis is about 0.98 dB and dB scale of
the de-emphasis is about -1.1 dB. It is not exact same value, so the signal power spectral
density and the magnitude of fft would be reduced a little bit.

Also, the emphasized magnitude is not large enough to effectively reduce the noise
power after the low pass filter. The reason why the de-emphasis filter did not de-
emphasize the noise power considerably is that the original signal power was also
decreased as the same degree of the noise. I wanted to get the signal power spectral
density as the same value, which was obtained at the previous m.file design, at the de-
emphasis filter.

In conclusion, based on the current filter designs, keeping the signal power and
reducing the noise power efficiently are limited. The following graphs will show how the
signal power has been emphasized by the pre-emphasis filter and its power spectral
density. The scale of PSD is decibel.

<The original signal fft and power spectral density after the pre-emphasis filter>

53
4. Signal and Noise Power Spectral Density Result

The next graphs compares the signal power spectral density between the un-emphasis
and emphasis case. The first (un-emphasis) and second (emphasis) graphs shows almost
same dB value at the center frequency 100 Hz (fm).

It means that the signal power is almost preserved constantly through pre and de-
emphasis filters.

Next, the major role of the emphasis filter is to reduce the noise power at higher
frequency range. The two following figures shows the pre/de-emphasis filters shrinks the
noise power near the 100 Hz (fm). The simulation parameters in two results are set same.
(Ac=2, Am=5, fc=500, fm=100, kf = 50, Beta = 2.5). The first graph is obtained after the
low pass filter at the receiver (umemphsized.m file), and the second one is obtained after
the de-emphasis filter at the receiver (emphasized.m file).

54
<Noise Power Spectral Density between un-emphasized and emphasized case>

55
The peaking point of Noise Power Spectral Density in the second graph is decrease a
little bit compared to the first one. The filters does not enhance SNR remarkably due to
the simple pre-emphasis filter design. I wanted to find the same signal power while
reducing the noise power, so it was unavoidable to limit the decreasing dB scale in de-
emphasis filter.

The next 2 pages will show FM threshold effect graphs and how the pre/de-emphasis
filters enhance the SNR in frequency modulation.

56
5. Simulation Result (FM threshold Effect)

Un-emphasized Case Emphasized Case

57
Un-emphasized Case Emphasized Case

58
Chapter 6. Conclusion

The FM threshold effect graphs are represented in different parameters. If the Beta
increases, the graphs are plotted above the linear line rising more sharply. When comparing
the un-emphasized and emphasized case, the non-linear point was shifted from lower SNR
to higher SNR point. This phenomena was represented remarkably when the Beta was
large.

To demonstrate the emphasis effect, I fixed the plot figure’s axis in each simulation. So,
in the un-emphasis plot figure, all the calculated point might not be recorded on the graph.
Plus, since the pre and de-emphasis filter were not designed well to reduce the noise
power effectively. I tried to simulate varying the fm which allows the bandwidth of single
tone input signal to be sufficiently overwhelmed within the unity gain range of the pre-
emphasis filter; however, due to the limit of frequency range (sampling fs = 2000Hz), the
fm could not be set large enough.

Also, the simulation has been executed only when the input signal was single cosine
signal. If I had more time to perform this design more accurately, I could have run this
model changing the input signal to multiple cosines or voice signals and designed pre-
emphasis filter completely.

Through this FM simulation, the demodulation and SNR of FM were simply demonstrated.
I hope that this design helps students to understand frequency modulation and
demodulation easily.

59
Appendix A- Matlab File List

Matlab File Name Contents

Analog_System m.file/fig Double Side Band Modulation

SSB_SC m.file/fig Single Side Band Modulation

Super_reciever m.file/fig Superheterodyne Receiver

Vestigial_Side_Modulation m.file Vestigial Side Band Modulation

Armstrong_Method m.file/fig Frequency Modulation

Emphasized/Unemphasized m.file FM Threshold Effect

generateBandPass/Stop m.file Minimum Order Filter Design

generateHigh/LowPass m.file Minimum Order Filter Design

env_phas m.file Envelope Detector Function_1

loweq m.file Envelope Detector Function_2

spower m.file Power calculation Function

Sample_Voice_1 ~ 4.wav Voice Sample (fs =8000 Hz)

Sampling_30khz_1 ~ 4.wav Voice Sample (fs =30 KHz)

Other Image Files Image Files for GUI Design

60
Appendix B- Function

1. Envelope Detector Implementation (My_First_Version.m / env_phas.m)

To demodulate AM or FM signals, non-coherent detector is widely used to recover


original signal. One of the conventional design of non-coherent detector is envelope
detector. I implemented the envelope detector in three different methods.

First method is based on the circuit parameters, such as diode, register, and capacitor.

Each element are designed ideally in my code. In detail, the


diode limits the input signal amplitude just like hard limiter,
and resistor and capacitor components are used to calculate
RC time constant.

Since the input signal’s amplitude is below 0.5 level, the cut off value of diode should
be set lower than real diode characteristics. If the diode’s cut-off voltage is set like 0.7, the
entire signal could not pass the diode.

Based on the textbook and communication theory print, the proper range of RC constant
1 1
value is set between 𝑎𝑛𝑑 (Fc is the carrier and Fm is the message frequency). In the
𝐹𝑐 𝐹𝑚
function, I set the RC value as the mean of the two value. But, in the GUI design, the fc
value could not be set much larger than the message bandwidth. It makes hard to decide
the proper RC range and degrades the envelope detector output because the fc and fm
are too closer to differentiate its frequency spectrum.

The following graphs are results of my first option (My_First_Version.m file). The
frequency domain shows that the mid band frequency are missed out and the quality of
the sound are degraded. This is because the fc and fm are close, and the process to follow
the envelope of the received signal could not detect the sensitive amplitudes between
each amplitudes of the signal. In the first plot figure, the orange line is detected signal.
The line starts decreasing when its amplitude passes the maximum point and stops
decreasing when the signal meets the received signal (blue color). The following algorithm
has been developed in my code.

61
<How the RC value detect the envelope (above) and the result (below)>

62
The second method is based on Hilbert transform method. This design is grounded on
the concept of analytic signal. Analytic signal is complex-valued function 1 and its
mathematical expression is like following one.

In case of double side band large carrier signal, the received signal is V(t)

V(t) = 1+a× m(t) ( a is constant value )

And the envelope of a band pass signal can be expressed as the magnitude of its low
pass equivalent signal2. Using these properties, V(t) could be written as in phasor and
quadrature component of low pass signal.

V(t) = √xi(t)2 + 𝑥𝑞(𝑡)2 (xi(t):real value, xq(t): the imaginary part of the received signal.)

The Hilbert transform leads the imaginary part of the signal. I used ‘env_phas’, ‘loweq’,
and ’fftseq’ functions described in ‘the Contemporary Communication System’.

This method is also well explained in the Matlab Central Internet site. In the web page3,
the lowpass filtering method and Hilbert transform method are introduced. The lowpass
design is effective when the carrier fc and the message bandwidth are well distinguished.
The filter’s stop and pass band allows only message band and cuts off the carrier spectrum;
However, in my GUI design, due to limitation of fc range, its implementation could not
derive the envelope of the signal.

The following capture images are the results when the input signal is single tone cosine
signal. I repeated this simulation varying the input signal form from single to double and
voice sample signal. The green color signal in the left side image is DSB-LC modulated
signal and red color signal is the detected enveloped signal. The right side shows each
frequency spectrum. The unit in time domain is seconds, and frequency domain is Hz. The
last case compares only frequency spectrum since the signal in time domain fluctuates too
fast to check the differences between input and output.

1
Page 118. Contemporary Communication System Using Matlab written by John G. Proakis

2
Page 37, Contemporary Communication System Using Matlab written by John G. Proakis

3
Matlab Central, ‘Envelope Detector Matlab Design’

63
<fm = 10, fc=250 single tone cosine case>

<fm1 = 10, fm2 = 30, fc = 250 two cosine signal case>

64
<input: ‘44100_sample_1.wav’ , fc = 50000Hz case>

2. Power Calculation Implementation (spower.m)

When calculating signal to noise ratio in dB scale or power of the signal, I used snr built in function
at the first GUI design. To know the power of signal using the definition of the signal, I made spower
function to calculate power.

65
Table of Contents
........................................................................................................................................ 1
Load File and Setting Basic Parameters .................................................................................. 1
diode expression ................................................................................................................. 1
RC tau Calculation .............................................................................................................. 2
Detection Output ................................................................................................................. 2
Lowpass Filter Design ......................................................................................................... 2
Plot the result ..................................................................................................................... 2

clear all;
clc;

Load File and Setting Basic Parameters


[wave,fs,nb] = wavread('44100_sample_1.wav');
t = 0:1/fs:(length(wave)-1)/fs;
wave_input = wave'; % to create same matrix as time domain.
m = length(wave); % window length
n1 = pow2(nextpow2(m)); % transform length
df = fs/n1; % freqency resolution (delta f)
f = (0:n1-1)*df-fs/2; % freqency domain

Warning: WAVREAD will be removed in a future release.


Use AUDIOREAD instead.

Fm = max(f);
Fc = Fm*50; %carrier frequency >> bandwidth Mhz unit
tau_min =1/Fc; %Lower bound of time constant
tau_max =1/Fm; %Upper bound of time constant
Tc = 10^(-6); %Sampling time of tau
tau = tau_min:Tc:tau_max;
num_tau=length(tau);
Ts=tau_min/100; %Sampling time

num_pts=length(t);
Envelope_Signal = wave_input; %t related function design
C1 = cos(2*pi*Fc*t);
Modulated_Signal = (Envelope_Signal+1).*C1;

diode expression
d = 0.05; %ideal diode cut
d_buffer = zeros(1,length(wave_input));
d_matrix = d*d_buffer(1:1:length(d_buffer));
diode_output = zeros(1,length(wave_input));
on = 1; %circuit pow
i =0;
while(on)
i = i+1;

1
66
buffer_matrix(1,i) = Modulated_Signal(1,i);
if (buffer_matrix(1,i) > d_matrix(1,i))
diode_output(1,i) = Modulated_Signal(1,i)-d_matrix(1,i);
else
diode_output(1,i) = zeros(1,1);
end
if(i >= length(Modulated_Signal))
on = 0;
else
on = 1;
end
end

RC tau Calculation
rr = (1/Fc +1/Fm)/2;

Detection Output
output_signal(1,1)=1;
for n=1:num_pts-1
if output_signal(1,n)<diode_output(1,n)
output_signal(1,n+1)=diode_output(1,n+1);
else
output_signal(1,n+1)=diode_output(1,n)*rr;
end
end

Lowpass Filter Design


%sampling freq --> 44100 / cutoff 5khz..
Lowpass_Filt = designfilt('lowpassfir','PassbandFrequency',0.25, ...
'StopbandFrequency',0.3,'PassbandRipple',0.5, ...
'StopbandAttenuation',65,'DesignMethod','kaiserwin');
Lowpass_result = filter(Lowpass_Filt,output_signal);
Result_fft = abs(fft(Lowpass_result,n1)/n1);
Result_fft_sh = circshift(Result_fft, [0 n1/2]);

Plot the result


figure(2);
subplot(1,3,1);
plot(Modulated_Signal);
title('Recieved Signal');
grid on;

subplot(1,3,2);
plot(output_signal);
title('envelope detector output ');
xlabel('Time(sec.)');
ylabel('Amplitude');

2
67
grid on;

subplot(1,3,3);
plot(t,Lowpass_result);
title('Lowpass output');
grid on;

figure(3);
%fft part
wave_fft = abs(fft(wave_input,n1)/n1);
wave_fft_sh = circshift(wave_fft, [0 n1/2]);
out_fft = abs(fft(output_signal,n1)/n1);
out_fft_sh = circshift(out_fft, [0 n1/2]);

subplot(1,3,1);
plot(f,wave_fft_sh);
axis([min(f) max(f) 0 1.3*10^-3]);
title('Original ');
subplot(1,3,2);
plot(f,out_fft_sh);
title('Detection Out');
axis([min(f) max(f) 0 1.3*10^-3]);
subplot(1,3,3);
plot(f,Result_fft_sh);
axis([min(f) max(f) 0 1.3*10^-3]);
title('Lowpass output');

3
68
Published with MATLAB® R2014a

4
69
Envelope_Detector
clear all;
clc;

[wave,fs,nb] = wavread('44100_sample_1.wav');
t = 0:1/fs:(length(wave)-1)/fs; %
wave_input= wave';
m =wave_input; % window length
n = pow2(nextpow2(length(wave))); % transform length
df = fs/n; % freqency resolution (delta f)
f = (0:n-1)*df-fs/2; % freqency domain
a = 0.8;
fc= 50000;
c = cos(2*pi*fc*t);

Warning: WAVREAD will be removed in a future release.


Use AUDIOREAD instead.

t0=0.2 ; % signal duration ts=0.001; % sampling interval fc=250; % carrier frequency a=0.8; % modu-
lation index fs=1/ts; % sampling frequency t=[0:ts:t0]; % time vector fm = 10; fm2 = 30; fm3 = 40; n
= pow2(nextpow2(length(t))); df=fs/n; % required frequency resolution f = (0:n-1)*df-fs/2; % freqency
domain % message signal m=cos(2*pi*fm*t)+cos(2*pi*fm2*t); c=cos(2*pi*fc*t);

Noise = wgn(1,length(m), 1); %white noise

%modulated signal
u =(1+a*m).*c;
%envelope
env=env_phas(u);
dem1=2*(env-1)/a; % Remove dc and rescale.

%fft
u_fft = abs(fft(u,n)/n);
u_fft_shifted = circshift(u_fft, [0 n/2]);
dem1_fft = abs(fft(dem1,n)/n);
dem1_fft_shifted = circshift(dem1_fft, [0 n/2]);

%plot
figure(1);
subplot(1,2,1);
plot(t,m);
title('original signal');
grid on;
subplot(1,2,2);
plot(t,u);
title('Modulated Signal');
grid on;

figure(2);
subplot(1,2,1);
plot(t,u);

1
70
title('Modulated Signal');
subplot(1,2,2);
plot(t,env);
title('Envelope Detection Output');

2
71
figure(3);
subplot(1,2,1);
plot(t,u, 'g');
hold on;
plot(t,env, 'r');
grid on;

subplot(1,2,2);
plot(f,u_fft_shifted, 'g');
hold on;
plot(f, dem1_fft_shifted, 'r');
axis([-25000 25000 0 1.4*10^(-3)]);
grid on;

3
72
figure(4);
subplot(1,2,1);
wave_input_fft =circshift(abs(fft(wave_input,n)/n), [0 n/2]);
plot(f,wave_input_fft);
title('Original Signal Spetrum');
xlabel('Hz');
grid on;

subplot(1,2,2);
plot(f, dem1_fft_shifted, 'r');
title('Envelope Detector Output Spectrum');
axis([-25000 25000 0 1.4*10^(-3)]);
xlabel('Hz');
grid on;

4
73
Published with MATLAB® R2014a

5
74
function p=spower(x)
% p=spower(x)
%SPOWER returns the power in signal x
p=(norm(x)^2)/length(x);

Error using spower (line 4)


Not enough input arguments.

Published with MATLAB® R2014a

1
75
Appendix C- Code

-Double Side Band Modulation

-Single Side Band Modulation

-Superheterodyne Receiver

-Vestigial Side Band Modulation

-Frequency Modulation

-FM Un-emphasis/Emphasis

76
Double Side Band Suppressed

Carrier Modulation

77
function varargout = Analog_System(varargin)
% ANALOG_SYSTEM MATLAB code for Analog_System.fig
% ANALOG_SYSTEM, by itself, creates a new ANALOG_SYSTEM or raises the existing
% singleton*.
%
% H = ANALOG_SYSTEM returns the handle to a new ANALOG_SYSTEM or the handle to
% the existing singleton*.
%
% ANALOG_SYSTEM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANALOG_SYSTEM.M with the given input arguments.
%
% ANALOG_SYSTEM('Property','Value',...) creates a new ANALOG_SYSTEM or raises
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Analog_System_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Analog_System_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Analog_System

% Last Modified by GUIDE v2.5 02-Apr-2015 15:52:30

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Analog_System_OpeningFcn, ...
'gui_OutputFcn', @Analog_System_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Analog_System is made visible.


function Analog_System_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

1
78
% varargin command line arguments to Analog_System (see VARARGIN)

% Choose default command line output for Analog_System

handles.fileLoaded_1 = 0; %wave file_1 existence judging element


handles.fileModulated_1 = 0; %modulation for signal 1 is not started
handles.filePreFiltered_1 = 0; %Pre Filtered signal 1 judging element

handles.DONE = 0;
handles.demod_1 = 0; %demodulation for 1

%modulation variables definition


set(handles.textStatic1, 'String', 'Carrier Fre (Hz):');
set(handles.editF1, 'Visible', 'On');

%filter variables definition


set(handles.textS1, 'String', 'Low Freq(Hz):');
set(handles.textS1,'Visible','On');
set(handles.textS2,'Visible','Off');
set(handles.editS2,'Visible','Off');
handles.SelectedFilter = 1; %set the lowpass filter on the f

handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Analog_System wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Analog_System_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in ButtonLoad1.


function ButtonLoad1_Callback(hObject, eventdata, handles)
% hObject handle to ButtonLoad1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% The Sampling Frequency is already setted as 8Khz when I recorded the


% sample voice 1 using matlab function-audiorecord.
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[x,Fs] = wavread([PathName '/' FileName]);
handles.x = x';

2
79
%to make same matrix with time domain
% If you want 'filter' command in the matlab, you should transpose the
% matrix. You can check the different result, unless you keep the same
% matrix form.
handles.Fs = Fs; %sampling frequency(800
m = length(handles.x); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain
handles.f = f;

%plot timedomain
axes(handles.axesSignal1);
time = 0:1/Fs:(length(handles.x)-1)/Fs;
handles.time = time;
plot(time, handles.x);
title('Sample Voice Signal 1');
axis([0 max(time) -1 1]);
grid on;

%plot fft part


axes(handles.axesfre1);
handles.wave_input = x';
y = abs(fft(handles.wave_input,n)/n);
y_shifted = circshift(y, [0 n/2]);
plot(f, y_shifted);
title('Frequency Spectrum');
grid on;

handles.fileLoaded_1 = 1; %complete fileload signal

guidata(hObject, handles);

% --- Executes on button press in playbutton1.


function playbutton1_Callback(hObject, eventdata, handles)
% hObject handle to playbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.fileLoaded_1 == 1)
sound(handles.x, handles.Fs);
end

% --- Executes on button press in WhiteNoise.


function WhiteNoise_Callback(hObject, eventdata, handles)
% hObject handle to WhiteNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function editF1_Callback(hObject, eventdata, handles)


% hObject handle to editF1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

3
80
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editF1 as text


% str2double(get(hObject,'String')) returns contents of editF1 as a double

% --- Executes during object creation, after setting all properties.


function editF1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editF1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in popupmenu1.


function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as c


% contents{get(hObject,'Value')} returns selected item from popupmenu1
% Role : determine the filter to minimize the original bandwidth of
% original signal
R = get(hObject, 'Value');

switch (R)
case (1) %low
set(handles.textS1,'String','Low Fre(HZ):');
set(handles.textS2,'Visible','Off');
set(handles.editS2,'Visible','Off');
handles.SelectedFilter = 1;
case (2) %high
set(handles.textS1,'String','High Fre (HZ):');
set(handles.textS2,'Visible','Off');
set(handles.editS1,'Visible','Off');
handles.SelectedFilter = 2;
end

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.

4
81
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editS1_Callback(hObject, eventdata, handles)


% hObject handle to editS1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editS1 as text


% str2double(get(hObject,'String')) returns contents of editS1 as a double

% --- Executes during object creation, after setting all properties.


function editS1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editS1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editS2_Callback(hObject, eventdata, handles)


% hObject handle to editS2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editS2 as text


% str2double(get(hObject,'String')) returns contents of editS2 as a double

% --- Executes during object creation, after setting all properties.


function editS2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editS2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Filtering.


function Filtering_Callback(hObject, eventdata, handles)

5
82
% hObject handle to Filtering (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.fileLoaded_1==1)

N = 300;

switch (handles.SelectedFilter)
case (1)
% Lowpass:
Fpass = str2num(get(handles.editS1,'String'));
if (length(Fpass)>0)
if (Fpass<handles.Fs/2-30)
Fstop = Fpass + 30;
handles.Fpass = Fpass;
handles.Fstop = Fstop;
Hd = generateLowPassFilter(Fpass, Fstop, handles.Fs, N);
DONE = 1;
else
msgbox('Frequency value is not in the correct range','Wrong Freq
end
else
msgbox('Missing Frequency values! Please fill in the missing values
end
case (2)
% Highpass:
Fpass = str2num(get(handles.editS1,'String'));
if (length(Fpass)>0)
if (Fpass<handles.Fs/2-30)
Fstop = Fpass - 30;
handles.Fpass = Fpass;
handles.Fstop = Fstop;
Hd = generateHighPassFilter(Fpass, Fstop, handles.Fs, N);
DONE = 1;
else
msgbox('Frequency value is not in the correct range','Wrong Fre
end
else
msgbox('Missing Frequency values! Please fill in the missing values
end

end

if(DONE == 1)
Pre_Filtered_1 = filter(Hd, 1, handles.x);
Pre_Filltered_1_fft = abs(fft(Pre_Filtered_1, handles.n)/handles.n);
Pre_Filtered_1_fft_sh = circshift(Pre_Filltered_1_fft, [0 handles.n/2]);
handles.filePreFiltered_1 = 1; %Filtered Complete Signal
handles.Pre_Filtered_1 = Pre_Filtered_1;
handles.fm = 4000;

axes(handles.axesFil1);
plot(handles.time, Pre_Filtered_1);

6
83
grid on;

axes(handles.axesFil2);
plot(handles.f, Pre_Filtered_1_fft_sh);
grid on;
end
end
guidata(hObject, handles);

% --- Executes on button press in Play.


function Play_Callback(hObject, eventdata, handles)
% hObject handle to Play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ( handles.filePreFiltered_1 == 1)
sound(handles.Pre_Filtered_1, handles.Fs);
end

% --- Executes on button press in Modulation.


function Modulation_Callback(hObject, eventdata, handles)
% hObject handle to Modulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%modulation part
fc = str2num(get(handles.editF1, 'String')); %get the carrier frequency info f
handles.fc = fc;
C1 = cos(2*pi*fc*handles.time);
S1 = handles.Pre_Filtered_1.*C1;
handles.S1 = S1;
handles.C1= C1;

axes(handles.axesmod1);
plot(handles.time,S1);
title('Modulated Signal 1');
grid on;
%fft
S1_fft = abs(fft(S1,handles.n)/handles.n);
S1_fft_sh = circshift(S1_fft, [0 handles.n/2]);

axes(handles.axesmod2);
plot(handles.f , S1_fft_sh);
title('Frequency Spectrum');
grid on;
guidata(hObject, handles);

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

7
84
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Demodulation.


function Demodulation_Callback(hObject, eventdata, handles)
% hObject handle to Demodulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
demod_fc = str2num(get(handles.edit5, 'String')); %get the carrier frequ
demod_phasor = str2num(get(handles.edit6, 'String')); %get the phasor error info
demod_C1 = cos(2*pi*demod_fc*handles.time+demod_phasor);
demod_S1 = handles.S1.*demod_C1; %demodulation
handles.demod_C1 = demod_C1;

%lowpass filter to pass only baseband signal(pre_filtered signal)


% the limited frequency would be the same frequency, which was used at the
% pre filtering lowpass filter.

N = 300;
Fre_limited =str2num(get(handles.editS1,'String'));
handles.Fm = Fre_limited; %setting band
Fre_stop = Fre_limited +30;
Hd =generateLowPassFilter(Fre_limited, Fre_stop, handles.Fs, N);
Base_Signal_1 = filter(Hd, 1, demod_S1); %baseband signal
handles.Base_Signal_1 = Base_Signal_1;
handles.demod_1 = 1;
%fft part
Base_Signal1_fft = abs(fft(Base_Signal_1, handles.n)/handles.n);
Base_Signal1_fft_sh = circshift(Base_Signal1_fft, [0 handles.n/2]);

%plot
axes(handles.axesdemod1);
plot(handles.time, Base_Signal_1);
grid on;
axes(handles.axesdemod2);
plot(handles.f, Base_Signal1_fft_sh);
grid on;

8
85
%correlation part
%segmention of signal

if(handles.demod_1 == 1)
%crosscorrelation of pre filtered signal 1 and no errored demod signal
[ac1,lags] = xcorr(handles.Pre_Filtered_1);
%crosscorrelation of pre filtered signal and errored demod signal
[ac2, lags] = xcorr(handles.Pre_Filtered_1, handles.Base_Signal_1);
end

axes(handles.axeauto1);
plot(lags, ac1);
grid on;
axes(handles.axescross1);
plot(lags,ac2);
grid on;

guidata(hObject, handles);

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in playresult.


function playresult_Callback(hObject, eventdata, handles)
% hObject handle to playresult (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sound(handles.Base_Signal_1, handles.Fs);

function editR_Callback(hObject, eventdata, handles)


% hObject handle to editR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

9
86
% Hints: get(hObject,'String') returns contents of editR as text
% str2double(get(hObject,'String')) returns contents of editR as a double

% --- Executes during object creation, after setting all properties.


function editR_CreateFcn(hObject, eventdata, handles)
% hObject handle to editR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editC_Callback(hObject, eventdata, handles)


% hObject handle to editC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editC as text


% str2double(get(hObject,'String')) returns contents of editC as a double

% --- Executes during object creation, after setting all properties.


function editC_CreateFcn(hObject, eventdata, handles)
% hObject handle to editC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton22.


function pushbutton22_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton22 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function editD_Callback(hObject, eventdata, handles)


% hObject handle to editD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editD as text

10
87
% str2double(get(hObject,'String')) returns contents of editD as a double

% --- Executes during object creation, after setting all properties.


function editD_CreateFcn(hObject, eventdata, handles)
% hObject handle to editD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in whitenoise.


function whitenoise_Callback(hObject, eventdata, handles)
% hObject handle to whitenoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% already modulated and filtered signal used(caution)


Noise = str2double(get(handles.editSNR, 'String'));
White_Noise = Noise*randn(1,length(handles.time));
Sum_Signal = White_Noise + handles.S1;
handles.Sum_Signal = Sum_Signal;
handles.White_Noise = White_Noise;

Sum_Singal_fft = abs(fft(Sum_Signal,handles.n)/handles.n);
Sum_Signal_fft_sh= circshift(Sum_Singal_fft, [0 handles.n/2]);

%plot
axes(handles.axes24);
plot(handles.time, Sum_Signal);
xlabel('time(sec)');
ylabel('amplitude');
grid on;
title('With Additive Gaussian White Noise');

axes(handles.axes26);
plot(handles.f, Sum_Signal_fft_sh);
grid on;
xlabel('frequency(Hz)');
ylabel('amplitude');
title('Frequency Spectrum');

guidata(hObject, handles);

% --- Executes on button press in PlayNoise.


function PlayNoise_Callback(hObject, eventdata, handles)
% hObject handle to PlayNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

11
88
% handles structure with handles and user data (see GUIDATA)
sound(handles.Sum_Signal_base, handles.Fs);

% --- Executes on button press in Demodulation2.


function Demodulation2_Callback(hObject, eventdata, handles)
% hObject handle to Demodulation2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%demodulation
%lowpass filter design with same structure
N = 300;
Fre_limited =str2num(get(handles.editS1,'String'));
handles.Fm = Fre_limited; %setting bandwidth
Fre_stop = Fre_limited +30;
Hd =generateLowPassFilter(Fre_limited, Fre_stop, handles.Fs, N);
Sum_Signal_demo = handles.Sum_Signal.*handles.C1;
Sum_Signal_base = filter(Hd,1,Sum_Signal_demo);

% baseband signal
Sum_Signal_base_fft = abs(fft(Sum_Signal_base,handles.n)/handles.n);
Sum_Signal_base_sh = circshift(Sum_Signal_base_fft, [0 handles.n/2]);

axes(handles.axes27);
plot(handles.time, Sum_Signal_base);
grid on;
axes(handles.axes29);
plot(handles.f, Sum_Signal_base_sh);
grid on;

guidata(hObject, handles);

% --- Executes on button press in togglebutton1.


function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1


EnvelopeDetection

% --- Executes during object creation, after setting all properties.


function axes28_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes28 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes28

function SNR_value_Callback(hObject, eventdata, handles)


% hObject handle to SNR_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

12
89
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of SNR_value as text


% str2double(get(hObject,'String')) returns contents of SNR_value as a doubl

% --- Executes during object creation, after setting all properties.


function SNR_value_CreateFcn(hObject, eventdata, handles)
% hObject handle to SNR_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in SNR_caculate.


function SNR_caculate_Callback(hObject, eventdata, handles)
% hObject handle to SNR_caculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

signal_power = handles.S1;
noise_power = handles.White_Noise;

SNR_Value = snr(signal_power,noise_power);

set(handles.SNR_value, 'String', [sprintf('%.1f',SNR_Value) ' '] );


guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function editSNR_CreateFcn(hObject, eventdata, handles)
% hObject handle to editSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');end

function editSNR_Callback(hObject, eventdata, handles)


% hObject handle to editSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editSNR as text

13
90
% str2double(get(hObject,'String')) returns contents of editSNR as a double

Published with MATLAB® R2014a

14
91
Single Side Band Suppressed

Carrier Modulation

92
function varargout = SSB_SC(varargin)
% SSB_SC MATLAB code for SSB_SC.fig
% SSB_SC, by itself, creates a new SSB_SC or raises the existing
% singleton*.
%
% H = SSB_SC returns the handle to a new SSB_SC or the handle to
% the existing singleton*.
%
% SSB_SC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SSB_SC.M with the given input arguments.
%
% SSB_SC('Property','Value',...) creates a new SSB_SC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SSB_SC_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SSB_SC_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help SSB_SC

% Last Modified by GUIDE v2.5 31-Mar-2015 00:37:36

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SSB_SC_OpeningFcn, ...
'gui_OutputFcn', @SSB_SC_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before SSB_SC is made visible.


function SSB_SC_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

1
93
% varargin command line arguments to SSB_SC (see VARARGIN)

% Choose default command line output for SSB_SC


handles.fileLoaded_1 = 0; %wave file_1 existence judging element
handles.fileModulated_1 = 0; %modulation for signal 1 is not started
handles.filePreFiltered_1 = 0; %Pre Filtered signal 1 judging element

handles.DONE = 0;
handles.demod_1 = 0; %demodulation for 1

%filter variables definition


set(handles.text1, 'String', 'Low Freq(Hz):');
set(handles.text1,'Visible','On');
set(handles.text2,'Visible','Off');
set(handles.edit2,'Visible','Off');
handles.SelectedFilter = 1; %set the lowpass filter on the f
%popupmenu_parameter
handles.side1 =1;
handles.side2 =1;
%demod_parameter
handles.demod_de =1;

%load images
axes(handles.axes17);
matlmg = imread('single1.jpg');
image(matlmg);
axis off
axis image
axes(handles.axes18);
matlmg2 = imread('single2.jpg');
image(matlmg2);
axis off
axis image

handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes SSB_SC wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = SSB_SC_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

2
94
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Phasormodulation.


function Phasormodulation_Callback(hObject, eventdata, handles)
% hObject handle to Phasormodulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%design hilbert transform of message signal


Hil_Signal = imag(hilbert(handles.Pre_Filtered_1));
S1 = sin(2*pi*handles.fc*handles.time); %sin(2*pi*handles.fc*handles.time);

% balanced modulator design


if (handles.side2 ==1)
%upper
output = handles.Pre_Filtered_1.*handles.C1 - Hil_Signal.*S1;
else
%lower
output = handles.Pre_Filtered_1.*handles.C1 + Hil_Signal.*S1;
end

handles.phase_output= output;

%fft
output_fft = abs(fft(output,handles.n)/handles.n);
output_fft_sh = circshift(output_fft, [0 handles.n/2]);

%plot
axes(handles.axes10);
plot(handles.time, output);
title('SSB');
xlabel('(sec)');

3
95
ylabel('amplitude');
grid on;

axes(handles.axes9);
plot(handles.f, output_fft_sh);
xlabel('(Hz)');
ylabel('amplitude');
grid on;

guidata(hObject, handles);

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in sidechoicemenu.


function sidechoicemenu_Callback(hObject, eventdata, handles)
% hObject handle to sidechoicemenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns sidechoicemenu contents


% contents{get(hObject,'Value')} returns selected item from sidechoicemenu

%upperside or lowerside decision making part


Side = get(hObject, 'Value');

side1 = 1; %set the default value

switch (Side)
case 1 %upper side
side1 =1;
case 2 %lower side
side1 =0;
end
handles.side1 = side1;
%later the value decide different filter.

4
96
guidata(hObject, handles);

% --- Executes on button press in BandPassModu.


function BandPassModu_Callback(hObject, eventdata, handles)
% hObject handle to BandPassModu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fc = str2num(get(handles.edit3, 'String'));
C1 = cos(2*pi*fc*handles.time);
handles.fc = fc;
handles.C1 = C1;
demod_signal = handles.Pre_Filtered_1 .*C1;
%check the mimumum frequency range to design bandpass filter
demod_fft = abs(fft(demod_signal, handles.n)/handles.n);
demod_fft_sh = circshift(demod_fft, [0 handles.n/2]);
mimum_range = abs(min(demod_fft_sh));

% filter design
N = 300; %filter order common

if (handles.side1 ==1)
%upper bandpass filter
Fpass1 = fc;
Fstop1 = fc-30;
Fstop2 = handles.fm;
Fpass2 = handles.fm-30; %focus only the cutoff region
Hd = generateBandPassFilter(Fpass1, Fstop1, Fpass2, Fstop2, handles.Fs, N);
else
%lower bandpass filter
Fpass1 = mimum_range+30;
Fstop1 = mimum_range;
Fstop2 = fc+30;
Fpass2 = fc; %focus only the cutoff region
Hd = generateBandPassFilter(Fpass1, Fstop1, Fpass2, Fstop2, handles.Fs, N);
end

SSB_result = filter(Hd,1,demod_signal);
handles.SSB_result = SSB_result;
%fft
SSB_result_fft = abs(fft(SSB_result, handles.n)/handles.n);
SSB_result_sh = circshift(SSB_result_fft, [0 handles.n/2]);

%plot
axes(handles.axes6)
plot(handles.time, SSB_result);
title('SSB');
xlabel('(sec)');
ylabel('amplitude');
grid on;

axes(handles.axes5)
plot(handles.f, SSB_result_sh);
title('SSB');
xlabel('(Hz)');

5
97
ylabel('amplitude');
grid on;

guidata(hObject, handles);

% --- Executes on selection change in popupmenu1.


function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as c


% contents{get(hObject,'Value')} returns selected item from popupmenu1
R = get(hObject, 'Value');

switch (R)
case (1) %low
set(handles.text1,'String','Low Fre(HZ):');
set(handles.text2,'Visible','Off');
set(handles.edit2,'Visible','Off');
handles.SelectedFilter = 1;
case (2) %high
set(handles.text1,'String','High Fre (HZ):');
set(handles.text2,'Visible','Off');
set(handles.editLow,'Visible','Off');
handles.SelectedFilter = 2;
end

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editLow_Callback(hObject, eventdata, handles)


% hObject handle to editLow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editLow as text


% str2double(get(hObject,'String')) returns contents of editLow as a double

% --- Executes during object creation, after setting all properties.

6
98
function editLow_CreateFcn(hObject, eventdata, handles)
% hObject handle to editLow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Filtering.


function Filtering_Callback(hObject, eventdata, handles)
% hObject handle to Filtering (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.fileLoaded_1==1)

handles.SelectedFilter =1 ;
N = 300;

switch (handles.SelectedFilter)
case (1)
% Lowpass:
Fpass = str2num(get(handles.editLow,'String'));
if (length(Fpass)>0)
if (Fpass<handles.Fs/2-30)
Fstop = Fpass + 30;
handles.Fpass = Fpass;
handles.Fstop = Fstop;

7
99
Hd = generateLowPassFilter(Fpass, Fstop, handles.Fs, N);
DONE = 1;
else
msgbox('Frequency value is not in the correct range','Wrong Freq
end
else
msgbox('Missing Frequency values! Please fill in the missing values
end

end

if(DONE == 1)
Pre_Filtered_1 = filter(Hd, 1, handles.x);
Pre_Filltered_1_fft = abs(fft(Pre_Filtered_1, handles.n)/handles.n);
Pre_Filtered_1_fft_sh = circshift(Pre_Filltered_1_fft, [0 handles.n/2]);
handles.filePreFiltered_1 = 1; %Filtered Complete Signal
handles.Pre_Filtered_1 = Pre_Filtered_1;
handles.fm = 4000;

axes(handles.axes4);
plot(handles.time, Pre_Filtered_1);
grid on;

axes(handles.axes3);
plot(handles.f, Pre_Filtered_1_fft_sh);
grid on;
end
end
guidata(hObject, handles);

% --- Executes on button press in Playsound2.


function Playsound2_Callback(hObject, eventdata, handles)
% hObject handle to Playsound2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sound(handles.Pre_Filtered_1, handles.Fs);

% --- Executes on button press in loadfile.


function loadfile_Callback(hObject, eventdata, handles)
% hObject handle to loadfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% The Sampling Frequency is already setted as 8Khz when I recorded the
% sample voice 1 using matlab function-audiorecord.
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[x,Fs] = wavread([PathName '/' FileName]);
handles.x = x';
%to make same matrix with time domain
% If you want 'filter' command in the matlab, you should transpose the
% matrix. You can check the different result, unless you keep the same

8
100
% matrix form.
handles.Fs = Fs; %sampling frequency(800
m = length(handles.x); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain
handles.f = f;
%plot timedomain
axes(handles.axes2);
time = 0:1/Fs:(length(handles.x)-1)/Fs;
handles.time = time;
plot(time, handles.x);
title('Sample Voice Signal 1');
axis([0 max(time) -1 1]);
grid on;

%plot fft part


axes(handles.axes1);
handles.wave_input = x';
y = abs(fft(handles.wave_input,n)/n);
y_shifted = circshift(y, [0 n/2]);
plot(f, y_shifted);
title('Frequency Spectrum');
grid on;

handles.fileLoaded_1 = 1; %complete fileload signal

guidata(hObject, handles);

% --- Executes on button press in playsound.


function playsound_Callback(hObject, eventdata, handles)
% hObject handle to playsound (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.fileLoaded_1 == 1)
sound(handles.x, handles.Fs);
end

function editCarri_Callback(hObject, eventdata, handles)


% hObject handle to editCarri (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editCarri as text


% str2double(get(hObject,'String')) returns contents of editCarri as a doubl

% --- Executes during object creation, after setting all properties.


function editCarri_CreateFcn(hObject, eventdata, handles)
% hObject handle to editCarri (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

9
101
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.


function sidechoicemenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to sidechoicemenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in popupmenu3.


function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as c


% contents{get(hObject,'Value')} returns selected item from popupmenu3
Side2 = get(hObject, 'Value');
switch (Side2)
case 1 %upper side
side2 =1;
case 2 %lower side
side2 =0;
end
handles.side2 = side2;
%later the value decide different filter.

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

10
102
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in demodulation.


function demodulation_Callback(hObject, eventdata, handles)
% hObject handle to demodulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%setting basic parameter


%get the carrier fc at the demodulation part
fc_demod = str2num(get(handles.edit11,'String'));
phase_demod = str2num(get(handles.edit13,'String'));
demo_C1 = cos(2*pi*fc_demod*handles.time+phase_demod);

%coherent detector
detector_input = handles.Sum_signal.*demo_C1;

%design lowpass filter to get baseband signal


N = 300; %filter order
%follow the bandwidth of the pre_filtered signal.
%it is recommanded to apply the pre filtering.
frepass = handles.Fpass;
frestop = handles.Fstop;
Hd = generateLowPassFilter(frepass, frestop, handles.Fs, N);

demodulated_signal = filter(Hd,1,detector_input);
handles.demodulated_signal = demodulated_signal;
%fft
demodulated_signal_fft = abs(fft(demodulated_signal, handles.n)/handles.n);
demodulated_signal_fft_sh = circshift(demodulated_signal_fft, [0 handles.n/2]);

11
103
%plot
axes(handles.axes12);
plot(handles.time,demodulated_signal);
title('demodulated signal');
xlabel('(sec)');
ylabel('(amplitude)');
grid on;

axes(handles.axes11);
plot(handles.f,demodulated_signal_fft_sh);
xlabel('(Hz)');
ylabel('(amplitude)');
grid on;

guidata(hObject, handles);

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Playdemodsound.


function Playdemodsound_Callback(hObject, eventdata, handles)
% hObject handle to Playdemodsound (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sound(handles.demodulated_signal, handles.Fs);

% --- Executes on selection change in popupmenu5.


function popupmenu5_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

12
104
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu5 contents as c
% contents{get(hObject,'Value')} returns selected item from popupmenu5
Y = get(hObject, 'Value');

switch (Y)
case 1
%bandpass demod
demod_de = 1;
case 2
%phase_shift demod
demod_de = 0;
end

handles.demod_de = demod_de;

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popupmenu5_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit8_Callback(hObject, eventdata, handles)


% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in whitenoise.

13
105
function whitenoise_Callback(hObject, eventdata, handles)
% hObject handle to whitenoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Noise = str2double(get(handles.editNoise, 'String'));
% get the noise time domain range from the pre filtered signal length
White_Noise = Noise*randn(size(handles.Pre_Filtered_1)); %uniform noi
handles.White_Noise = White_Noise;
voltage_gain = str2double(get(handles.edit12,'String'));

%this part takes two input modulated signal (bandpass/phase shift)


%decide which one will be demodulated by the popupmenu5.

if (handles.demod_de ==1)
%bandpass
demodulating_signal = handles.SSB_result;
else
%phase_shift
demodulating_signal = handles.phase_output;
end
%to amplify the output because of the decreasing result(see the manual for
%the detail)

Amplified_signal = voltage_gain.*demodulating_signal;
handles.Ampllified_signal = Amplified_signal;
Sum_signal = White_Noise+Amplified_signal;
handles.Sum_signal = Sum_signal;

guidata(hObject, handles);

function editNoise_Callback(hObject, eventdata, handles)


% hObject handle to editNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editNoise as text


% str2double(get(hObject,'String')) returns contents of editNoise as a doubl

% --- Executes during object creation, after setting all properties.


function editNoise_CreateFcn(hObject, eventdata, handles)
% hObject handle to editNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

14
106
function editSNR_Callback(hObject, eventdata, handles)
% hObject handle to editSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editSNR as text


% str2double(get(hObject,'String')) returns contents of editSNR as a double

% --- Executes during object creation, after setting all properties.


function editSNR_CreateFcn(hObject, eventdata, handles)
% hObject handle to editSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in SNRCaculate.


function SNRCaculate_Callback(hObject, eventdata, handles)
% hObject handle to SNRCaculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
signal_power = handles.Ampllified_signal;
noise_power = handles.White_Noise;

SNR_Value = snr(signal_power,noise_power);

set(handles.editSNR, 'String', [sprintf('%.1f',SNR_Value) ' '] );


guidata(hObject, handles);

function edit11_Callback(hObject, eventdata, handles)


% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text


% str2double(get(hObject,'String')) returns contents of edit11 as a double

% --- Executes during object creation, after setting all properties.


function edit11_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

15
107
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit12_Callback(hObject, eventdata, handles)


% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit12 as text


% str2double(get(hObject,'String')) returns contents of edit12 as a double

% --- Executes during object creation, after setting all properties.


function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit13_Callback(hObject, eventdata, handles)


% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit13 as text


% str2double(get(hObject,'String')) returns contents of edit13 as a double

% --- Executes during object creation, after setting all properties.


function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

16
108
Published with MATLAB® R2014a

17
109
Super Heterodyne Receiver

110
function varargout = super_reciever(varargin)
% SUPER_RECIEVER MATLAB code for super_reciever.fig
% SUPER_RECIEVER, by itself, creates a new SUPER_RECIEVER or raises the existi
% singleton*.
%
% H = SUPER_RECIEVER returns the handle to a new SUPER_RECIEVER or the handle
% the existing singleton*.
%
% SUPER_RECIEVER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SUPER_RECIEVER.M with the given input arguments.
%
% SUPER_RECIEVER('Property','Value',...) creates a new SUPER_RECIEVER or raise
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before super_reciever_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to super_reciever_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help super_reciever

% Last Modified by GUIDE v2.5 20-May-2015 03:35:42

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @super_reciever_OpeningFcn, ...
'gui_OutputFcn', @super_reciever_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before super_reciever is made visible.


function super_reciever_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

1
111
% varargin command line arguments to super_reciever (see VARARGIN)

% Choose default command line output for super_reciever


handles.fileLoaded_1 = 0;
handles.fileLoaded_2 = 0;
handles.fileLoaded_3 = 0;
handles.fileLoaded_4 = 0;

%popupmenu_1 parameter setting


handles.selection = 1;
%load image files here
axes(handles.axes5);
matlabImage = imread('super1.jpg');
image(matlabImage);
axis off
axis image
axes(handles.axes7);
matlabImage2 = imread('super2.jpg');
image(matlabImage2);
axis off
axis image

handles.output = hObject;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes super_reciever wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = super_reciever_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in pushbutton8.


function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ( handles.fileLoaded_4 ==1)
sound(handles.u, handles.Fs);
end

% --- Executes on button press in pushbutton7.


function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)

2
112
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[u,Fs] = wavread([PathName '/' FileName]);
handles.u = u';
handles.Fs = Fs; %sampling frequency(800
m = length(handles.u); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain
handles.fileLoaded_4 = 1;

guidata(hObject, handles);

% --- Executes on button press in pushbutton6.


function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ( handles.fileLoaded_3 ==1)
sound(handles.z, handles.Fs);
end

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[z,Fs] = wavread([PathName '/' FileName]);
handles.z = z';
handles.Fs = Fs; %sampling frequency(800
m = length(handles.z); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain

handles.fileLoaded_3 = 1;

guidata(hObject, handles);

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ( handles.fileLoaded_2 ==1)
sound(handles.y, handles.Fs);
end

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)

3
113
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[y,Fs] = wavread([PathName '/' FileName]);
handles.y = y';
handles.Fs = Fs; %sampling frequency(800
m = length(handles.y); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain
handles.fileLoaded_2 = 1;

guidata(hObject, handles);

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[x,Fs] = wavread([PathName '/' FileName]);
handles.x = x';
%to make same matrix with time domain
% If you want 'filter' command in the matlab, you should transpose the
% matrix. You can check the different result, unless you keep the same
% matrix form.
handles.Fs = Fs; %sampling frequency(800
m = length(handles.x); %window length
n = pow2(nextpow2(m)); %transform length
handles.n = n;
df =Fs / n; %frequency resolu
f = (0:n-1).*df - Fs/2; %frequency domain
handles.f = f;
time = 0:1/Fs:(length(handles.x)-1)/Fs;

handles.time = time;
handles.fileLoaded_1 = 1;

guidata(hObject, handles);

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ( handles.fileLoaded_1 ==1)
sound(handles.x, handles.Fs);
end

4
114
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton12.


function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton14.


function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton15.


function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton19.


function pushbutton19_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton18.


function pushbutton18_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton18 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton17.


function pushbutton17_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

5
115
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)

6
116
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Modulation_4.


function Modulation_4_Callback(hObject, eventdata, handles)
% hObject handle to Modulation_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fc4 = str2num(get(handles.edit8,'String'));
C4 = cos(2*pi*handles.time*fc4);
Modulated_4 = handles.u.*C4;
handles.Modulated_4 = Modulated_4;
handles.C4 = C4;
handles.fc4 = fc4;
% to avoid interferance effect with other signals.
if (fc4 > 15000)
msgbox('Modulation is done', 'Success');
else
msgbox('Please rewrite the carrier frequency', 'Error', 'error');
end
guidata(hObject, handles);

function edit8_Callback(hObject, eventdata, handles)

7
117
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Modulation_3.


function Modulation_3_Callback(hObject, eventdata, handles)
% hObject handle to Modulation_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fc3 = str2num(get(handles.edit7,'String'));
C3 = cos(2*pi*handles.time*fc3);
Modulated_3 = handles.z.*C3;
handles.Modulated_3 = Modulated_3;
handles.C3 = C3;
handles.fc3 = fc3;
% to avoid interferance effect with other signals.
if (fc3 > 15000)
msgbox('Modulation is done', 'Success');
else
msgbox('Please rewrite the carrier frequency', 'Error', 'error');
end
guidata(hObject, handles);

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

8
118
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Modulation_2.


function Modulation_2_Callback(hObject, eventdata, handles)
% hObject handle to Modulation_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fc2 = str2num(get(handles.edit6,'String'));
C2 = cos(2*pi*handles.time*fc2);
Modulated_2 = handles.y.*C2;
handles.Modulated_2 = Modulated_2;
handles.C2 = C2;
handles.fc2 = fc2;
% to avoid interferance effect with other signals.
if (fc2 > 15000)
msgbox('Modulation is done', 'Success');
else
msgbox('Please rewrite the carrier frequency', 'Error', 'error');
end
guidata(hObject, handles);

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Modulation_1.


function Modulation_1_Callback(hObject, eventdata, handles)

9
119
% hObject handle to Modulation_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%get the carrier frequency info


fc1 = str2num(get(handles.edit5,'String'));
C1 = cos(2*pi*handles.time*fc1);
Modulated_1 = handles.x.*C1;
handles.Modulated_1 = Modulated_1;
handles.fc1 = fc1;
handles.C1 = C1;
if (fc1 > 15000)
msgbox('Modulation is done', 'Success');
else
msgbox('Please rewrite the carrier frequency', 'Error', 'error');
end
guidata(hObject, handles);

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in RF_channel.


function RF_channel_Callback(hObject, eventdata, handles)
% hObject handle to RF_channel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on selection change in popupmenu1.


function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

10
120
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as c
% contents{get(hObject,'Value')} returns selected item from popupmenu1
selected_signal = get(hObject, 'Value');
% just check the signal parameter
switch (selected_signal)
case 1 %1 signal
selection =1;
case 2 %2 signal
selection = 2;
case 3 %3signal
selection = 3;
case 4 %4signal
selection = 4;
end
handles.selection = selection;

guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editLocal_Callback(hObject, eventdata, handles)


% hObject handle to editLocal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editLocal as text


% str2double(get(hObject,'String')) returns contents of editLocal as a doubl

% --- Executes during object creation, after setting all properties.


function editLocal_CreateFcn(hObject, eventdata, handles)
% hObject handle to editLocal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');

11
121
end

% --- Executes on button press in pushbutton40.


function pushbutton40_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton40 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

f_IF = str2num(get(handles.editIF,'String'));
if (f_IF <= 5000)
msgbox('The Intermediate frequency is lower than the signal bandwidth','Error',
success_term = 0;
else
msgbox('Proper Intermediate frequency', 'Success');
success_term = 1;
end
%Double Side Band Case--> f_lF must be determined larger than the original
%signal bandwidth.
% f_LO = fc +f_IF(fixed value) / > 4000
% popupmenu input check to calcute f_LO
% f_LO value is your choice
if (success_term == 1)

switch (handles.selection)
case 1
f_LO = handles.fc1+f_IF;
selected_output = handles.Modulated_1;
plotted_signal = handles.x;
case 2
f_LO = handles.fc2+f_IF;
selected_output = handles.Modulated_2;
plotted_signal = handles.y;
case 3
f_LO = handles.fc3+f_IF;
selected_output = handles.Modulated_3;
plotted_signal = handles.z;
case 4
f_LO = handles.fc4+f_IF;
selected_output = handles.Modulated_4;
plotted_signal = handles.z;
end
handles.selected_output = selected_output;
handles.plotted_signal = plotted_signal;
Local_C = cos(2*pi*handles.time*f_LO);
set(handles.editLocal, 'String', [sprintf('%.1f',f_LO) ' '] );
filter_input = selected_output.*Local_C;
handles.filter_input = filter_input;

else
msgbox('Please try again!!','Error','error');
end
guidata(hObject, handles);

12
122
function editIF_Callback(hObject, eventdata, handles)
% hObject handle to editIF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editIF as text


% str2double(get(hObject,'String')) returns contents of editIF as a double

% --- Executes during object creation, after setting all properties.


function editIF_CreateFcn(hObject, eventdata, handles)
% hObject handle to editIF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit11_Callback(hObject, eventdata, handles)


% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text


% str2double(get(hObject,'String')) returns contents of edit11 as a double

% --- Executes during object creation, after setting all properties.


function edit11_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function edit12_Callback(hObject, eventdata, handles)


% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit12 as text


% str2double(get(hObject,'String')) returns contents of edit12 as a double

13
123
% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Detection.


function Detection_Callback(hObject, eventdata, handles)
% hObject handle to Detection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
final_fc =str2num(get(handles.edit11,'String'));
final_phasor = str2num(get(handles.edit12,'String'));
final_gain = str2num(get(handles.edit13,'String'));

final_C1 = final_gain*cos(2*pi*final_fc*handles.time+final_phasor);

wanted_signal = handles.filter_input.*final_C1;
%design lowpass filter to get baseband signal
N = 300;
frepass = 5000;
frestop = 5100;
Hd = generateLowPassFilter(frepass, frestop, handles.Fs, N);

wanted_signal_output = filter(Hd, 1,wanted_signal);


handles.wanted_signal_output = wanted_signal_output;
wanted_signal_output_fft = circshift(abs(fft(wanted_signal_output, handles.n)/handl

axes(handles.axes3);
plot(handles.time, wanted_signal_output, 'g');
grid on;
title('Received Signal');
xlabel('sec');
ylabel('amplitude');
axes(handles.axes4);
plot(handles.f, wanted_signal_output_fft, 'r');
grid on;
title('Received Signal');
xlabel('Hz');
ylabel('amplitude');

guidata(hObject, handles);

% --- Executes on button press in PlayFinal.

14
124
function PlayFinal_Callback(hObject, eventdata, handles)
% hObject handle to PlayFinal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sound(handles.wanted_signal_output, handles.Fs);

function edit13_Callback(hObject, eventdata, handles)


% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit13 as text


% str2double(get(hObject,'String')) returns contents of edit13 as a double

% --- Executes during object creation, after setting all properties.


function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on key press with focus on Detection and none of its controls.
function Detection_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to Detection (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in Help.


function Help_Callback(hObject, eventdata, handles)
% hObject handle to Help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox('This UI will demonstrate how the superheterodyne reciever recieves the sign

% --- Executes on button press in Help2.


function Help2_Callback(hObject, eventdata, handles)
% hObject handle to Help2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox('You should decide the carrier frequency over the bandwidth of the signal(50

15
125
% --- Executes on button press in Help3.
function Help3_Callback(hObject, eventdata, handles)
% hObject handle to Help3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox('The RF Section button does not filter the signal in this design. It would b

Published with MATLAB® R2014a

16
126
Frequency Modulation/Demodulation

And FM Threshold Effect

127
function varargout = Armstrong_Method(varargin)
% ARMSTRONG_METHOD MATLAB code for Armstrong_Method.fig
% ARMSTRONG_METHOD, by itself, creates a new ARMSTRONG_METHOD or raises the ex
% singleton*.
%
% H = ARMSTRONG_METHOD returns the handle to a new ARMSTRONG_METHOD or the han
% the existing singleton*.
%
% ARMSTRONG_METHOD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ARMSTRONG_METHOD.M with the given input arguments
%
% ARMSTRONG_METHOD('Property','Value',...) creates a new ARMSTRONG_METHOD or r
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Armstrong_Method_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Armstrong_Method_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Armstrong_Method

% Last Modified by GUIDE v2.5 28-May-2015 00:51:56

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Armstrong_Method_OpeningFcn, ...
'gui_OutputFcn', @Armstrong_Method_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Armstrong_Method is made visible.


function Armstrong_Method_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

1
128
% varargin command line arguments to Armstrong_Method (see VARARGIN)

%check the cos / voice


handles.choice = 1;

%fileLoad Parameter
handles.fileLoad_1 = 0;
%narrowFM Parameter
handles.narrowfc = 0;
handles.narrowkf = 0;

% Choose default command line output for Armstrong_Method


handles.output = hObject;
%initial image setting
set(handles.editAm,'Visible','on');
set(handles.editFm,'Visible','on');
set(handles.PlaySound, 'Visible', 'off');
set(handles.text6, 'Visible', 'on');
set(handles.text7, 'Visible', 'on');
set(handles.editAm2,'Visible', 'off');
set(handles.editAm3,'Visible', 'off');
set(handles.textAm2, 'Visible', 'off');
set(handles.editFm1, 'Visible', 'off');
set(handles.editFm2, 'Visible', 'off');
set(handles.textFm2, 'Visible', 'off');
%import image part
axes(handles.axes5);
matlabImage = imread('s.png');
image(matlabImage);
axis off
axis image
axes(handles.axes6);
matlabImage = imread('s.png');
image(matlabImage);
axis off
axis image
axes(handles.axes8);
matlabImage3 = imread('diff2.png');
image(matlabImage3);
axis off
axis image
axes(handles.axes11);
matlabImage4= imread('Filter_1.png');
image(matlabImage4);
axis off
axis image
axes(handles.axes10);
image(matlabImage);
axis off
axis image
axes(handles.axes9);
matlabImage5 = imread('envelope1.png');
image(matlabImage5);
axis off

2
129
axis image
axes(handles.axes14);
matlabImage6 = imread('Hard_Limiter2.png');
image(matlabImage6);
axis off
axis image
axes(handles.axes18);
matlabImage7 = imread('FM_Image_total.jpg');
image(matlabImage7);
axis off
axis image

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Armstrong_Method wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Armstrong_Method_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on selection change in popupmenu1.


function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as c


% contents{get(hObject,'Value')} returns selected item from popupmenu1
selection = get(hObject, 'Value');

switch (selection)
case 1 %cos
handles.choice = 1;
set(handles.editAm,'Visible','on');
set(handles.editFm,'Visible','on');
set(handles.PlaySound, 'Visible', 'off');
set(handles.text6, 'Visible', 'on');
set(handles.text7, 'Visible', 'on');
set(handles.editAm2,'Visible', 'off');
set(handles.editAm3,'Visible', 'off');
set(handles.textAm2, 'Visible', 'off');
set(handles.editFm1, 'Visible', 'off');
set(handles.editFm2, 'Visible', 'off');
set(handles.textFm2, 'Visible', 'off');

case 2 %multiple case

3
130
handles.choice = 2;
set(handles.editAm,'Visible','off');
set(handles.editFm,'Visible','off');
set(handles.PlaySound, 'Visible', 'off');
set(handles.text6, 'Visible', 'off');
set(handles.text7, 'Visible', 'off');
set(handles.editAm2,'Visible', 'on');
set(handles.editAm3,'Visible', 'on');
set(handles.textAm2, 'Visible', 'on');
set(handles.editFm1, 'Visible', 'on');
set(handles.editFm2, 'Visible', 'on');
set(handles.textFm2, 'Visible', 'on');

end

guidata(hObject, handles);

% --- Executes on button press in LoadFile.


function LoadFile_Callback(hObject, eventdata, handles)
% hObject handle to LoadFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% load voice file
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t0 = 500; %signal duration
ts = 0.0005; %time period
handles.ts=ts;
fs = 1/ts;
handles.fs = fs;
t=[0:ts:t0]; % time vector
handles.t = t;
n = pow2(nextpow2(length(t)));
handles.n = n;
df=fs/n; % required frequency resolution
f = (0:n-1)*df-fs/2; % freqency domain
handles.f = f;
switch (handles.choice)

case 1
%cosine signal case
%define basic parameter
% decide Fm and Am (make another edit and show the box)
%and add help button to show the basic info(ts and to)
Am = str2double(get(handles.editAm,'String'));
fm = str2double(get(handles.editFm,'String'));
handles.fm = fm;
handles.Am = Am;
message = Am*cos(2*pi*fm*t);
handles.message = message;

case 2

4
131
%multiple case
Am2 = str2double(get(handles.editAm2,'String'));
Am3 = str2double(get(handles.editAm3,'String'));
fm2 = str2double(get(handles.editFm1,'String'));
fm3 = str2double(get(handles.editFm2,'String'));
message = Am2*cos(2*pi*fm2*t) +Am3*cos(2*pi*fm3*t);
handles.message = message;

%define the fm/Am value


handles.Am = Am2+Am3;
%required to define frequency deviation
if (fm2 >= fm3 )
handles.fm = fm2;
else
handles.fm =fm3;
end

end
%fft
m_fft = abs(fft(message,n)/n);
m_fft_shifted = circshift(m_fft, [0 n/2]);
%plot
axes(handles.axes1);
plot(t,message);
xlabel('Time')
title('The message signal');
grid on;
axes(handles.axes2);
plot(f,m_fft_shifted);
xlabel('Frqeuncy')
title('The message signal');
grid on;

guidata(hObject, handles);

% --- Executes on button press in PlaySound.


function PlaySound_Callback(hObject, eventdata, handles)
% hObject handle to PlaySound (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Multi1.
if (handles.fileLoad_1 ==1)
sound(handles.BandLimited_Signal, handles.Fs);
end

% --- Executes on button press in NarrowGenerate.


function NarrowGenerate_Callback(hObject, eventdata, handles)
% hObject handle to NarrowGenerate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

5
132
%clear the old data in the plot figure
cla(handles.axes1);
cla(handles.axes2);

% get the Fc and Kf value


narrow_fc = str2double(get(handles.editNarrowfc,'String'));
narrow_kf = str2double(get(handles.editNarrowkf,'String'));
handles.narrow_fc = narrow_fc;
handles.narrow_kf = narrow_kf;

%in case of sinusoidal signal


if (handles.choice ==1 || handles.choice == 2)
%fc must be larger than fm hz
%kf satisfies narrow band FM
% check the range of each
if (narrow_fc < handles.fm)
handles.narrowfc_okay = 0;
mgsbox('The Carrier must be larger than the bandwidth of the message signal.
else
handles.narrowfc_okay= 1;
end

if (narrow_kf > 20)


handles.narrowkf_okay = 0;
else
handles.narrowkf_okay = 1;
end

% message integral part


int_m(1)=0; %the first el
for i=1:length(handles.t)-1
int_m(i+1)=int_m(i)+handles.message(i)* handles.ts;
end

%narrow_band_FM
NarrowBand_FM = cos(2*pi*narrow_fc*handles.t + 2*pi*narrow_kf*int_m);
handles.NarrowBand_FM = NarrowBand_FM;

%fft and plot the narrow band signal


NarrowBand_FM_fft = circshift(abs(fft(NarrowBand_FM, handles.n)/handles.n), [0 hand
handles.NarrowBand_FM_fft = NarrowBand_FM_fft;

axes(handles.axes1);
plot(handles.t, handles.NarrowBand_FM );
grid on;
title('Wide Band FM Signal');
xlabel('(sec)');
ylabel('(Magnitude)');

axes(handles.axes2);
plot(handles.f, handles.NarrowBand_FM_fft);
grid on;
title('Frequency Spectrum');
xlabel('(Hz)');

6
133
ylabel('(Normalized Magnitude)');

%Parameter checking
delta_f = handles.narrow_kf.*handles.Am;
handles.delta.f = delta_f;
beta = handles.delta.f / handles.fm;
handles.beta = beta;
bandwidth = 2*(handles.beta+1).*handles.fm; %carson's rule
handles.bandwidth = bandwidth;

set(handles.editfigureKf, 'String', [sprintf('%.1f',handles.narrow_kf ) ' '] );


set(handles.editfiguredeltaf, 'String', [sprintf('%.1f', handles.delta.f ) ' ']
set(handles.editBeta, 'String', [sprintf('%.1f',handles.beta ) ' '] );
set(handles.editfigureBand, 'String', [sprintf('%.1f',handles.bandwidth ) ' '] )

else
%blank

end

guidata(hObject, handles);

% --- Executes on button press in NoiseGenerate.


function NoiseGenerate_Callback(hObject, eventdata, handles)
% hObject handle to NoiseGenerate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%clear old data


cla(handles.axes1);
cla(handles.axes2);

%get the value


Noise = str2double(get(handles.editNoise, 'String'));
White_Noise = Noise*randn(1,length(handles.NarrowBand_FM));
Total_Signal = White_Noise + handles.NarrowBand_FM;
handles.total_signal = Total_Signal;
handles.White_Noise = handles.total_signal-handles.NarrowBand_FM;

%fft
Total_Signal_fft = circshift(abs(fft(Total_Signal, handles.n)/handles.n), [0 handle

%plot the signal


axes(handles.axes1);
plot(handles.t, handles.total_signal);
title('Recieved Signal');
xlabel('time');
grid on;

axes(handles.axes2);
plot(handles.f, Total_Signal_fft);
title('Recieved Signal');
xlabel('frequency');

7
134
grid on;

guidata(hObject, handles);

function Pre_Filtering_Callback(hObject, eventdata, handles)


% hObject handle to Pre_Filtering (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%Goal : Pre-SNR calculation

%clear old data


cla(handles.axes1);
cla(handles.axes2);

%Design bandpass filter at fc


%get the bandwidth using carson's rule
half_bandwidth = handles.bandwidth/2;
Fpass1 = handles.narrow_fc-half_bandwidth.*0.99;
Fstop1 = handles.narrow_fc-half_bandwidth;
Fpass2 = handles.narrow_fc+half_bandwidth.*0.99;
Fstop2 = handles.narrow_fc+half_bandwidth;

bpFilt = designfilt('bandpassfir','FilterOrder',50, ...


'CutoffFrequency1',Fstop1,'CutoffFrequency2',Fstop2, ...
'SampleRate',handles.fs);
handles.bpFilt = bpFilt;

%the length of input must be more than three times the filter order
Only_Signal_result = filtfilt(bpFilt,handles.NarrowBand_FM);
Bandpass_result = filtfilt(bpFilt,handles.total_signal);
handles.Bandpass_result = Bandpass_result;
handles.Only_Signal_result = Only_Signal_result;
%fft
handles.Bandpass_result_fft = circshift(abs(fft(Bandpass_result, handles.n)/handles
handles.Only_Signal_result_fft = circshift(abs(fft(Only_Signal_result, handles.n)/h

%plot
axes(handles.axes1);
plot(handles.t,Bandpass_result);
title('Bandpass Signal');
xlabel('time');
grid on;

axes(handles.axes2);
plot(handles.f, handles.Bandpass_result_fft);
title('Bandpass Signal');
xlabel('frequency');
grid on;

guidata(hObject, handles);

8
135
function Limiter_Callback(hObject, eventdata, handles)
% hObject handle to Limiter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Pre_Filtering.

cla(handles.axes1);
cla(handles.axes2);

%limit the amplitude of total_signal.


%I set the Ac = 1, only the white noise will affect the amplitude.
for i = 1:length(handles.Bandpass_result)
if (handles.Bandpass_result(i) > 0.5)
handles.limited_signal(i) = 0.5;
elseif(handles.Bandpass_result(i) < -0.5)
handles.limited_signal(i) = -0.5;
else
handles.limited_signal(i) = handles.Bandpass_result(i);
end
end
%if done, check only signal components
% handles.NarrowBand_FM only process starts!
for i = 1:length(handles.Only_Signal_result)
if (handles.Only_Signal_result(i) > 0.5)
handles.only_signal(i) = 0.5;
elseif(handles.Only_Signal_result(i) < -0.5)
handles.only_signal(i) = -0.5;
else
handles.only_signal(i) = handles.Only_Signal_result(i);
end
end

%fft
handles.limited_signal_fft = circshift(abs(fft(handles.limited_signal, handles.n)/h
axes(handles.axes1);
plot(handles.t,handles.limited_signal);
title('Bandpass Signal');
xlabel('time');
grid on;

axes(handles.axes2);
plot(handles.f, handles.limited_signal_fft);
title('Bandpass Signal');
xlabel('frequency');
grid on;

guidata(hObject, handles);

% --- Executes on button press in Pre_SNR_Cal.


function Pre_SNR_Cal_Callback(hObject, eventdata, handles)
% hObject handle to Pre_SNR_Cal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

9
136
%show the signal and noise psd and calculate pre-SNR
[Noise_PSD, f_domain] = pwelch(handles.limited_signal- handles.only_signal, 300, 2
[Signal_PSD,f_domain] = pwelch(handles.limited_signal, 300, 200, 300, handles.fs);
figure(1);
subplot(1,2,1);
plot(f_domain, 10*log10(Signal_PSD));
title('BandPass Filtered Signal PSD');
xlabel('Hz');
ylabel('dB');
grid on;
subplot(1,2,2);
plot(f_domain, 10*log10(Noise_PSD));
title('BandPass Filtered White Noise PSD');
xlabel('Hz');
ylabel('dB');
grid on;

%power calculation
Signal_P = spower(handles.only_signal);
Noise_P = spower(handles.only_signal- handles.limited_signal);
Noise_P2 = spower(handles.White_Noise);
Pre_SNR = Signal_P / Noise_P;
handles.Pre_SNR = pow2db(Pre_SNR); %filtered signal
UnF_SNR = Signal_P / Noise_P2; %unfiltered signal
handles.UnF_SNR = pow2db(UnF_SNR);
handles.Signal_P = Signal_P;

set(handles.editPreSNR1, 'String', [sprintf('%.3f',handles.UnF_SNR ) ' '] );


set(handles.editPreSNR2, 'String', [sprintf('%.3f',handles.Pre_SNR ) ' '] );

guidata(hObject, handles);

function EnvelopeDetector_Callback(hObject, eventdata, handles)


% hObject handle to EnvelopeDetector (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%clear old data


cla(handles.axes1);
cla(handles.axes2);

[Detector_FM_Signal, Signal_phasor] = env_phas(handles.limited_signal, handles.ts,h


[Detector_FM_Signal_only, Signal_phasor_only] = env_phas(handles.only_signal, hand
%detect the phasor term
signal_phi = unwrap(Signal_phasor);
signal_phi_only = unwrap(Signal_phasor_only);
%differentiator
signal_phasor(1) = 0;
for i=1:length(handles.t)-1
signal_phasor(i+1) = (signal_phi(i+1) - signal_phi(i))/(handles.ts);
end
signal_phasor_only(1)=0;
for i=1:length(handles.t)-1
signal_phasor_only(i+1) = (signal_phi_only(i+1) - signal_phi_only(i))/(handles.

10
137
end

handles.signal_phi= signal_phasor/(2*pi);
handles.signal_phi_only = signal_phasor_only/ (2*pi);
handles.signal_phi_fft = circshift(abs(fft(handles.signal_phi, handles.n)/handles.n
%plot the signal
axes(handles.axes1);
plot(handles.t,handles.signal_phi);
title('Envelope Signal');
xlabel('Time');
grid on;
axes(handles.axes2);
plot(handles.f, handles.signal_phi_fft);
title('Envelope Signal');
xlabel('Frequency');
grid on;

guidata(hObject, handles);

% --- Executes on button press in LowpassFilt.


function LowpassFilt_Callback(hObject, eventdata, handles)
% hObject handle to LowpassFilt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%clear old data


cla(handles.axes1);
cla(handles.axes2);

%cut off the damaged signal due to the differentitation


%and make the signal smoothly
Pass_f = (handles.fm) / (handles.fs/2);
Stop_f = (handles.fm*1.1) / (handles.fs/2);
Lowpass_filt = designfilt('lowpassfir','PassbandFrequency',Pass_f, ...
'StopbandFrequency',Stop_f,'PassbandRipple',0.1, ...
'StopbandAttenuation',65,'DesignMethod','kaiserwin');
handles.Lowpass_filt = Lowpass_filt;
Lowpass_out = filtfilt(Lowpass_filt, handles.signal_phi);
Lowpass_out_signal = filtfilt(Lowpass_filt, handles.signal_phi_only);
handles.Lowpass_out = Lowpass_out;
handles.Lowpass_out_signal = Lowpass_out_signal;

%total signal fft


Lowpass_out_fft = abs(fft(Lowpass_out,handles.n)/handles.n);
Lowpass_out_fft_shifted = circshift(Lowpass_out_fft, [0 handles.n/2]);
%signal only fft
Lowpass_out_signal_fft = abs(fft(Lowpass_out_signal,handles.n)/handles.n);
Lowpass_out_signal_fft_shifted = circshift(Lowpass_out_signal_fft, [0 handles.n/2]
handles.Lowpass_out_signal_fft_shifted = Lowpass_out_signal_fft_shifted;
%noise calculation
handles.final_noise = handles.Lowpass_out - handles.Lowpass_out_signal;
%noise fft

11
138
final_noise_fft =abs(fft(handles.final_noise,handles.n)/handles.n);
final_noise_fft_shifted = circshift(final_noise_fft, [0 handles.n/2]);
handles.final_noise_fft_shifted = final_noise_fft_shifted;

%plot
axes(handles.axes1);
plot(handles.t,handles.Lowpass_out );
title('Lowpass Filtered Signal');
xlabel('Time');
grid on;
axes(handles.axes2);
plot(handles.f, Lowpass_out_fft_shifted);
title('Lowpass Filtered Signal');
xlabel('Frequency');
grid on;

guidata(hObject, handles);

% --- Executes on button press in PostSNRcal.


function PostSNRcal_Callback(hObject, eventdata, handles)
% hObject handle to PostSNRcal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Post_Noise_PSD, f_domain] = pwelch(handles.final_noise, 300, 100, 300, handles.fs)
[Post_Signal_PSD, f_domain] = pwelch(handles.Lowpass_out_signal , 300, 100, 300, ha
Post_Noise_P = spower(handles.final_noise);
Post_Signal_P = spower(handles.Lowpass_out_signal);
Post_SNR = Post_Signal_P / Post_Noise_P;
handles.Post_SNR = pow2db(Post_SNR);

set(handles.editPostSNR, 'String', [sprintf('%.3f',handles.Post_SNR ) ' '] );


figure(2);
subplot(1,2,1);
plot(f_domain, 10*log10(Post_Signal_PSD));
title('Singal PSD after the lowpass filter');
xlabel('Hz');
ylabel('dB');
grid on;
subplot(1,2,2);
plot(f_domain, 10*log10(Post_Noise_PSD));
title('Noise PSD after the lowpass filter');
xlabel('Hz');
ylabel('dB');
grid on;
figure(3);
%plot each of fft result
subplot(1,2,1);
plot(handles.f,handles.Lowpass_out_signal_fft_shifted);
title('Only Singal Spetrum');
xlabel('Hz');
ylabel('Normalized Magnitude');
grid on;
subplot(1,2,2);
plot(handles.f, handles.final_noise_fft_shifted);

12
139
title('Only Noise Spetrum');
xlabel('Hz');
ylabel('Normalized Magnitude');
grid on;

guidata(hObject, handles);

% --- Executes on button press in EffectSimulation.


function EffectSimulation_Callback(hObject, eventdata, handles)
% hObject handle to EffectSimulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%import the simulation result from another m-file

guidata(hObject, handles);

function editNarrowfc_Callback(hObject, eventdata, handles)


% hObject handle to editNarrowfc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editNarrowfc as text


% str2double(get(hObject,'String')) returns contents of editNarrowfc as a do

% --- Executes during object creation, after setting all properties.


function editNarrowfc_CreateFcn(hObject, eventdata, handles)
% hObject handle to editNarrowfc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editNarrowkf_Callback(hObject, eventdata, handles)


% hObject handle to editNarrowkf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editNarrowkf as text


% str2double(get(hObject,'String')) returns contents of editNarrowkf as a do

% --- Executes during object creation, after setting all properties.


function editNarrowkf_CreateFcn(hObject, eventdata, handles)
% hObject handle to editNarrowkf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

13
140
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.


function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editAm_Callback(hObject, eventdata, handles)


% hObject handle to editAm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editAm as text


% str2double(get(hObject,'String')) returns contents of editAm as a double

% --- Executes during object creation, after setting all properties.


function editAm_CreateFcn(hObject, eventdata, handles)
% hObject handle to editAm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editFm_Callback(hObject, eventdata, handles)


% hObject handle to editFm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFm as text


% str2double(get(hObject,'String')) returns contents of editFm as a double

% --- Executes during object creation, after setting all properties.


function editFm_CreateFcn(hObject, eventdata, handles)
% hObject handle to editFm (see GCBO)

14
141
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editNoise_Callback(hObject, eventdata, handles)


% hObject handle to editNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editNoise as text


% str2double(get(hObject,'String')) returns contents of editNoise as a doubl

% --- Executes during object creation, after setting all properties.


function editNoise_CreateFcn(hObject, eventdata, handles)
% hObject handle to editNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.


function axes5_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes5

function editfigureKf_Callback(hObject, eventdata, handles)


% hObject handle to editfigureKf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

15
142
% Hints: get(hObject,'String') returns contents of editfigureKf as text
% str2double(get(hObject,'String')) returns contents of editfigureKf as a do

% --- Executes during object creation, after setting all properties.


function editfigureKf_CreateFcn(hObject, eventdata, handles)
% hObject handle to editfigureKf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editfiguredeltaf_Callback(hObject, eventdata, handles)


% hObject handle to editfiguredeltaf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editfiguredeltaf as text


% str2double(get(hObject,'String')) returns contents of editfiguredeltaf as

% --- Executes during object creation, after setting all properties.


function editfiguredeltaf_CreateFcn(hObject, eventdata, handles)
% hObject handle to editfiguredeltaf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editBeta_Callback(hObject, eventdata, handles)


% hObject handle to editBeta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editBeta as text


% str2double(get(hObject,'String')) returns contents of editBeta as a double

% --- Executes during object creation, after setting all properties.


function editBeta_CreateFcn(hObject, eventdata, handles)
% hObject handle to editBeta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

16
143
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editfigureBand_Callback(hObject, eventdata, handles)


% hObject handle to editfigureBand (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editfigureBand as text


% str2double(get(hObject,'String')) returns contents of editfigureBand as a

% --- Executes during object creation, after setting all properties.


function editfigureBand_CreateFcn(hObject, eventdata, handles)
% hObject handle to editfigureBand (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editPreSNR1_Callback(hObject, eventdata, handles)


% hObject handle to editPreSNR1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editPreSNR1 as text


% str2double(get(hObject,'String')) returns contents of editPreSNR1 as a dou

% --- Executes during object creation, after setting all properties.


function editPreSNR1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editPreSNR1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

17
144
function editPreSNR2_Callback(hObject, eventdata, handles)
% hObject handle to editPreSNR2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editPreSNR2 as text


% str2double(get(hObject,'String')) returns contents of editPreSNR2 as a dou

% --- Executes during object creation, after setting all properties.


function editPreSNR2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editPreSNR2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editPostSNR_Callback(hObject, eventdata, handles)


% hObject handle to editPostSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editPostSNR as text


% str2double(get(hObject,'String')) returns contents of editPostSNR as a dou

% --- Executes during object creation, after setting all properties.


function editPostSNR_CreateFcn(hObject, eventdata, handles)
% hObject handle to editPostSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.


function PostSNRcal_CreateFcn(hObject, eventdata, handles)
% hObject handle to PostSNRcal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

18
145
function editPostNoise_Callback(hObject, eventdata, handles)
% hObject handle to editPostNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editPostNoise as text


% str2double(get(hObject,'String')) returns contents of editPostNoise as a d

% --- Executes during object creation, after setting all properties.


function editPostNoise_CreateFcn(hObject, eventdata, handles)
% hObject handle to editPostNoise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Stop.


function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton27.


function pushbutton27_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton27 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function editAm2_Callback(hObject, eventdata, handles)


% hObject handle to editAm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editAm2 as text


% str2double(get(hObject,'String')) returns contents of editAm2 as a double

% --- Executes during object creation, after setting all properties.


function editAm2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editAm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

19
146
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editAm3_Callback(hObject, eventdata, handles)


% hObject handle to editAm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editAm3 as text


% str2double(get(hObject,'String')) returns contents of editAm3 as a double

% --- Executes during object creation, after setting all properties.


function editAm3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editAm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

function editFm1_Callback(hObject, eventdata, handles)


% hObject handle to editFm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFm1 as text


% str2double(get(hObject,'String')) returns contents of editFm1 as a double

% --- Executes during object creation, after setting all properties.


function editFm1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editFm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

20
147
function editFm2_Callback(hObject, eventdata, handles)
% hObject handle to editFm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFm2 as text


% str2double(get(hObject,'String')) returns contents of editFm2 as a double

% --- Executes during object creation, after setting all properties.


function editFm2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editFm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in popupmenu2.


function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as c


% contents{get(hObject,'Value')} returns selected item from popupmenu2

% --- Executes during object creation, after setting all properties.


function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in BandpassF2.


function BandpassF2_Callback(hObject, eventdata, handles)
% hObject handle to BandpassF2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

switch (handles.choice)
case 2
%multiple signal case
%how to design the bandwidth of the signal?

21
148
case 3
%digital signal case

end

guidata(hObject, handles);
% --- Executes on button press in LowpassF2.
function LowpassF2_Callback(hObject, eventdata, handles)
% hObject handle to LowpassF2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in Envelope2.


function Envelope2_Callback(hObject, eventdata, handles)
% hObject handle to Envelope2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in Diiferenatiate2.


function Diiferenatiate2_Callback(hObject, eventdata, handles)
% hObject handle to Diiferenatiate2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in Pre_Emphasis.


function Pre_Emphasis_Callback(hObject, eventdata, handles)
% hObject handle to Pre_Emphasis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in De_Emphasis.


function De_Emphasis_Callback(hObject, eventdata, handles)
% hObject handle to De_Emphasis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

22
149
Published with MATLAB® R2014a

23
150
Un-emphasis Case m.file

151
Table of Contents
Only Signal Case ................................................................................................................ 1
Setting Variables ................................................................................................................. 1
Noise ................................................................................................................................ 1
FM Modulation ................................................................................................................... 1
Bandpass Filter ................................................................................................................... 2
Limiter .............................................................................................................................. 2
Pre-SNR ............................................................................................................................ 2
Phasor Detector / differenentiator ........................................................................................... 2
Lowpass Filter .................................................................................................................... 3
Post SNR ........................................................................................................................... 3
Plot figure .......................................................................................................................... 3
noise psd plot ..................................................................................................................... 4

Only Signal Case


clear all;
clc;

Setting Variables
Am = 5;
fm = 100;
fc = 500;
kf = 50;
t0 = 5000;
ts = 0.0005;
fs = 1/ts;
t = [0: ts:t0];
message = Am*cos(2*pi*fm*t);
n = pow2(nextpow2(length(t)));
df = fs/n;
f = (0:n-1)*df-fs/2;
cnt = 1;
Amp = 0.7;
while(cnt)

Noise
Noise = Amp*randn(1,length(t));

FM Modulation
int_m(1) = 0;
for i=1:length(t)-1
int_m(i+1)=int_m(i)+message(i)*ts;
end
Ac = 2;
FM_signal = Ac*cos(2*pi*fc*t +2*pi*kf*int_m)+Noise;

1
152
FM_signal_only = Ac*cos(2*pi*fc*t +2*pi*kf*int_m);
FM_noise = FM_signal-FM_signal_only;
% define FM parameter
delta_f = kf*Am;
beta = delta_f / fm;
bandwidth = 2*(beta+1)*fm;

Bandpass Filter
half_bandwidth = bandwidth/2;
Fpass1 = fc-half_bandwidth.*0.99;
Fstop1 = fc-half_bandwidth;
Fpass2 = fc+half_bandwidth.*0.99;
Fstop2 = fc+half_bandwidth;

bpFilt = designfilt('bandpassfir','FilterOrder',50, ...


'CutoffFrequency1',Fstop1,'CutoffFrequency2',Fstop2, ...
'SampleRate',fs);
Only_Signal_result = filtfilt(bpFilt,FM_signal_only);
Total_result = filtfilt(bpFilt, FM_signal);

Limiter
for i = 1:length(Total_result)
if (Total_result(i) > 0.5)
limited_FM_signal(i) = 0.5;
elseif(Total_result(i) < -0.5)
limited_FM_signal(i) = -0.5;
else
limited_FM_signal(i) = Total_result(i);
end
end
for i = 1:length(Only_Signal_result)
if (Only_Signal_result(i) > 0.5)
limited_signal(i) = 0.5;
elseif(Only_Signal_result(i) < -0.5)
limited_signal(i) = -0.5;
else
limited_signal(i) = Only_Signal_result(i);
end
end

Pre-SNR
Signal_P = spower(limited_signal);
Noise_P = spower(limited_FM_signal-limited_signal);
Pre_SNR = Signal_P / Noise_P ;
Pre_SNR_db = pow2db(Pre_SNR);

Phasor Detector / differenentiator


%simulation only signal case

2
153
[Detector_Total_Signal, Total_phasor] = env_phas(FM_signal,ts,fc);
[Detector_FM_Signal, Signal_phasor] = env_phas(limited_signal, ts,fc);
total_phi = unwrap(Total_phasor);
total_phasor =(diff(total_phi)/(2*pi));
signal_phi = unwrap(Signal_phasor);
signal_phasor = (diff(signal_phi)/(2*pi));

Lowpass Filter
Pass_f = fm/ (fs/2);
Stop_f = fm*1.1 / (fs/2);
Lowpass_filt = designfilt('lowpassfir','PassbandFrequency',Pass_f, ...
'StopbandFrequency',Stop_f,'PassbandRipple',0.1, ...
'StopbandAttenuation',10,'DesignMethod','kaiserwin');

Lowpass_total = filtfilt(Lowpass_filt, total_phasor);


Lowpass_signal = filtfilt(Lowpass_filt, signal_phasor);
Lowpass_noise = Lowpass_total-Lowpass_signal;

Post SNR
Singal_P2 = spower(Lowpass_signal);
Noise_P2 = spower(Lowpass_noise);
Post_SNR = Singal_P2 / Noise_P2 ;
Post_SNR_db = pow2db(Post_SNR);

figure(3);
scatter(Pre_SNR_db, Post_SNR_db);
axis([6 15 12 32]);
hold on;
Amp = Amp -0.02;
if(Amp <= 0.2);
cnt =0;
xlabel('Pre_SNR(dB)');
ylabel('Post_SNR(dB)');
grid on;
else
cnt =1;
end

end

Plot figure
message_fft = circshift(abs(fft(Am*cos(2*pi*fm*t),n)/n), [0 n/2]);
Lowpass_total_fft = circshift(abs(fft(Lowpass_total,n)/n), [0 n/2]);
Lowpass_signal_fft = circshift(abs(fft(Lowpass_signal,n)/n), [0 n/2]);
Lowpass_noise_fft = circshift(abs(fft(Lowpass_noise,n)/n), [0 n/2]);
figure(1);
subplot(1,3,1);
plot(f,Lowpass_total_fft);
title('Total');

3
154
subplot(1,3,2);
plot(f,Lowpass_signal_fft);
title('Signal');
subplot(1,3,3);
plot(f,Lowpass_noise_fft);
title('Noise');

noise psd plot


[Noise_ouput_PSD,f_domain] = pwelch(Lowpass_noise, 300,200,300,fs);
[Lowpass_signal_PSD, f_domain] = pwelch(Lowpass_signal, 300,200,300,fs);

figure(2);
subplot(1,2,1);
plot(f_domain, 10*log10(Noise_ouput_PSD));
grid on;
xlabel('Hz');
ylabel('dB');
title('Noise Power Spectral Density (lowpass filter)');
figure(4);
plot(f_domain, 10*log10(Lowpass_signal_PSD));
grid on;
xlabel('Hz');
ylabel('dB');
title('Signal Power Spectral Density (lowpass filter)');

Published with MATLAB® R2014a

4
155
Emphasis Case m.file

156
Table of Contents
Pre Emphaszied Simulation ................................................................................................... 1
Setting Variables ................................................................................................................. 1
Pre_Emphasis ..................................................................................................................... 1
Noise ................................................................................................................................ 1
FM Modulation ................................................................................................................... 2
Bandpass Filter ................................................................................................................... 2
Limiter .............................................................................................................................. 2
Pre-SNR ............................................................................................................................ 3
Phasor Detector / differenentiator ........................................................................................... 3
Lowpass Filter .................................................................................................................... 3
De_Emphasis Filter( IIR lowpass filter) .................................................................................. 3
Post SNR ........................................................................................................................... 3
PSD and fft plot figure ........................................................................................................ 4

Pre Emphaszied Simulation


clear all;
clc;

Error: File: C:\Users\##\Google ####\Project\1\GUI Project\FM_therhold_effe


Unexpected MATLAB expression.

Setting Variables
Am = 5;
fm = 100;
fc = 500;
kf = 50;
t0 = 5000;
ts = 0.0005;
fs = 1/ts;
t = [0: ts:t0];
pure_message = Am*cos(2*pi*fm*t);
n = pow2(nextpow2(length(t)));
df = fs/n;
f = (0:n-1)*df-fs/2;
cnt = 1;
Amp = 0.7;
while(cnt)

Pre_Emphasis
Pre_Emphasis_Filt = [2.5 -1.5];
message = filter(Pre_Emphasis_Filt, 1,pure_message);

Noise
Noise = Amp*randn(1,length(t));

1
157
FM Modulation
int_m(1) = 0;
for i=1:length(t)-1
int_m(i+1)=int_m(i)+message(i)*ts;
end
Ac = 2;
FM_signal = Ac*cos(2*pi*fc*t +2*pi*kf*int_m)+Noise;
FM_signal_only = Ac*cos(2*pi*fc*t +2*pi*kf*int_m);
FM_noise = FM_signal-FM_signal_only;
% define FM parameter
delta_f = kf*Am;
beta = delta_f / fm;
bandwidth = 2*(beta+1)*fm;

Bandpass Filter
half_bandwidth = bandwidth/2;
Fpass1 = fc-half_bandwidth.*0.99;
Fstop1 = fc-half_bandwidth;
Fpass2 = fc+half_bandwidth.*0.99;
Fstop2 = fc+half_bandwidth;

bpFilt = designfilt('bandpassfir','FilterOrder',50, ...


'CutoffFrequency1',Fstop1,'CutoffFrequency2',Fstop2, ...
'SampleRate',fs);
Only_Signal_result = filtfilt(bpFilt,FM_signal_only);
Total_result = filtfilt(bpFilt, FM_signal);

Limiter
for i = 1:length(Total_result)
if (Total_result(i) > 0.5)
limited_FM_signal(i) = 0.5;
elseif(Total_result(i) < -0.5)
limited_FM_signal(i) = -0.5;
else
limited_FM_signal(i) = Total_result(i);
end
end
for i = 1:length(Only_Signal_result)
if (Only_Signal_result(i) > 0.5)
limited_signal(i) = 0.5;
elseif(Only_Signal_result(i) < -0.5)
limited_signal(i) = -0.5;
else
limited_signal(i) = Only_Signal_result(i);
end
end

2
158
Pre-SNR
Signal_P = spower(limited_signal);
Noise_P = spower(limited_FM_signal-limited_signal);
Pre_SNR = Signal_P / Noise_P ;
Pre_SNR_db = pow2db(Pre_SNR);

Phasor Detector / differenentiator


%simulation only signal case

[Detector_Total_Signal, Total_phasor] = env_phas(FM_signal,ts,fc);


[Detector_FM_Signal, Signal_phasor] = env_phas(limited_signal, ts,fc);
total_phi = unwrap(Total_phasor);
total_phasor =(diff(total_phi)/(2*pi));
signal_phi = unwrap(Signal_phasor);
signal_phasor = (diff(signal_phi)/(2*pi));

Lowpass Filter
Pass_f = fm/ (fs/2);
Stop_f = fm*1.1 / (fs/2);
Lowpass_filt = designfilt('lowpassfir','PassbandFrequency',Pass_f, ...
'StopbandFrequency',Stop_f,'PassbandRipple',0.1, ...
'StopbandAttenuation',10,'DesignMethod','kaiserwin');

Lowpass_total = filtfilt(Lowpass_filt, total_phasor);


Lowpass_signal = filtfilt(Lowpass_filt, signal_phasor);

De_Emphasis Filter( IIR lowpass filter)


de_emphasis_Filt = designfilt('lowpassiir','FilterOrder',2, ...
'PassbandFrequency',fm*1.2/2,'PassbandRipple',0.2, ...
'SampleRate',fs);
de_emphasized_total= filtfilt(de_emphasis_Filt,Lowpass_total);
de_emphasized_signal = filtfilt(de_emphasis_Filt, Lowpass_signal);
de_emphasized_noise = de_emphasized_total-de_emphasized_signal;

Post SNR
Singal_P2 = spower(de_emphasized_signal);
Noise_P2 = spower(de_emphasized_noise);
Post_SNR = Singal_P2 / Noise_P2 ;
Post_SNR_db = pow2db(Post_SNR);

figure(1);
scatter(Pre_SNR_db, Post_SNR_db);
hold on;
Amp = Amp -0.02;

3
159
end of the simulation
if(Amp <= 0.2);
cnt =0;
xlabel('Pre_SNR(dB)');
ylabel('Post_SNR(dB)');
grid on;
else
cnt =1;
end

end

PSD and fft plot figure


Lowpass_noise = Lowpass_total-Lowpass_signal;
[Lowpass_noise_PSD, f_domain] = pwelch(Lowpass_noise, 300,200,300,fs);

figure(2);
pure_message_fft = circshift(abs(fft(pure_message,n)/n), [0 n/2]);
messgae_fft = circshift(abs(fft(message,n)/n), [0 n/2]);
[pure_message_PSD, f_domain] = pwelch(pure_message, 300,200,300,fs);
[message_PSD, f_domain] = pwelch(message, 300,200,300,fs);
subplot(2,2,1);
plot(f,pure_message_fft);
title('Original Message')
subplot(2,2,2);
plot(f,messgae_fft);
title('Pre Emphasis Message');
subplot(2,2,3);
plot(f_domain, pure_message_PSD);
title('PSD');
subplot(2,2,4);
plot(f_domain, message_PSD);
title('PSD');

[de_emphasized_noise_PSD, f_domain] = pwelch(de_emphasized_noise, 300,200,300,fs);


de_emphasized_noise_fft = circshift(abs(fft(de_emphasized_noise,n)/n), [0 n/2]);
[de_emphasized_signal_PSD, f_domain] = pwelch(de_emphasized_signal, 300,200,300,fs)
de_emphasized_signal_fft = circshift(abs(fft(de_emphasized_signal,n)/n), [0 n/2]);

figure(3);
plot(f_domain, 10*log10(Lowpass_noise_PSD));
title('Lowpass Noise PSD');
xlabel('Hz');
ylabel('dB');
grid on;

figure(4);
plot(f_domain,10*log10(de_emphasized_noise_PSD));
title('De_emphasized Noise PSD');
xlabel('Hz');
ylabel('dB');
grid on;

4
160
figure(5);
plot(f_domain,10*log10(de_emphasized_signal_PSD));
title('De emphasized Signal PSD');

Published with MATLAB® R2014a

5
161
References
[1] Page 9: Korean J Otorhinolaryngology-Head Neck Surg 2008;51:1099-103, DOI
0.3342/kjorlhns.2008.51.12.1099

[2] Page 16: Communication Theory Chapter 3 page 111 figure (1)

[3] Page 20: Introduction to Analog and Digital Communication written by Moher

[4] Page 20: EE 160 pdf, Spring 2010 San Jose State University

[5] Page 21: Page 3, EE 160 pdf, Spring 2010 San Jose State University

[6] Page 25: Page 4, EE 160 pdf, Spring 2010 San Jose State University

[7] Page 27: Page 126, chapter 3.7 Superheterodyne receiver in the Communication Theory
print context

[8] Page 29: Page 45, Chapter 3, Communication Theory Print PDF

[9] Page 30: Page 8, Lecture #11, Vestigial Side Band Modulation KEEE 343 Communication
Theory pdf

[10] Page 37: Page 146, Chapter 4, Communication Theory PDF

[11] Page 37: Page 216, Modern Digital And Analog Communication System 4th edition
written by B.P. Lathi

[12] Page 49: DAE notes-1, (Pre and De-emphasized filter introduction)

[13] Page 51: DAE notes-2, (Pre and De-emphasized filter introduction)

[14] Page 63: Page 118. Contemporary Communication System Using Matlab written by
John G. Proakis

[15] Page 63: Page 37, Contemporary Communication System Using Matlab written by
John G. Proakis

[16] Page 63: Matlab Central, ‘Envelope Detector Matlab Design’

*Contact Information*
Email: honglee2335@gmail.com
Phone: 82-10-2301-0626

View publication stats

You might also like