Professional Documents
Culture Documents
net/publication/277871349
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.
Final Report
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).
5
Chapter 2 Background
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.
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
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.
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.
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
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.
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 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
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.
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.
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.
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.
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.
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.
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 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
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.
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.
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.
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.
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.
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
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
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
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
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.
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.
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)
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.
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.
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
𝑘𝑘𝑘𝑘𝑘𝑘𝑘𝑘
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)
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
60
Appendix B- Function
First method is based on the circuit parameters, such as diode, register, and capacitor.
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)
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>
64
<input: ‘44100_sample_1.wav’ , fc = 50000Hz case>
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;
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
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);
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);
%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);
1
75
Appendix C- Code
-Superheterodyne Receiver
-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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
1
78
% varargin command line arguments to Analog_System (see VARARGIN)
handles.DONE = 0;
handles.demod_1 = 0; %demodulation for 1
handles.output = hObject;
% --- 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)
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;
guidata(hObject, handles);
3
80
% handles structure with handles and user data (see GUIDATA)
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);
4
81
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroun
set(hObject,'BackgroundColor','white');
end
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);
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);
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
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);
9
86
% Hints: get(hObject,'String') returns contents of editR as text
% str2double(get(hObject,'String')) returns contents of editR as a double
10
87
% str2double(get(hObject,'String')) returns contents of editD as a double
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);
11
88
% handles structure with handles and user data (see GUIDATA)
sound(handles.Sum_Signal_base, handles.Fs);
% 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);
12
89
% 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);
13
90
% str2double(get(hObject,'String')) returns contents of editSNR as a double
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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
1
93
% varargin command line arguments to SSB_SC (see VARARGIN)
handles.DONE = 0;
handles.demod_1 = 0; %demodulation for 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;
% --- 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)
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)
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);
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);
% 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);
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);
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
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);
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;
guidata(hObject, handles);
9
101
% handles empty - handles not created until after all CreateFcns called
guidata(hObject, handles);
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)
%coherent detector
detector_input = handles.Sum_signal.*demo_C1;
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);
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);
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'));
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);
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)
SNR_Value = snr(signal_power,noise_power);
15
107
% 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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
1
111
% varargin command line arguments to super_reciever (see VARARGIN)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- 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)
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);
handles.fileLoaded_3 = 1;
guidata(hObject, 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);
handles.time = time;
handles.fileLoaded_1 = 1;
guidata(hObject, handles);
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)
5
115
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
6
116
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
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)
8
118
% handles empty - handles not created until after all CreateFcns called
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)
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);
11
121
end
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)
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
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);
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);
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);
% --- 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)
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
16
126
Frequency Modulation/Demodulation
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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
1
128
% varargin command line arguments to Armstrong_Method (see VARARGIN)
%fileLoad Parameter
handles.fileLoad_1 = 0;
%narrowFM Parameter
handles.narrowfc = 0;
handles.narrowkf = 0;
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
% --- 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)
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');
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);
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;
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);
5
132
%clear the old data in the plot figure
cla(handles.axes1);
cla(handles.axes2);
%narrow_band_FM
NarrowBand_FM = cos(2*pi*narrow_fc*handles.t + 2*pi*narrow_kf*int_m);
handles.NarrowBand_FM = NarrowBand_FM;
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;
else
%blank
end
guidata(hObject, handles);
%fft
Total_Signal_fft = circshift(abs(fft(Total_Signal, handles.n)/handles.n), [0 handle
axes(handles.axes2);
plot(handles.f, Total_Signal_fft);
title('Recieved Signal');
xlabel('frequency');
7
134
grid on;
guidata(hObject, handles);
%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);
%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);
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;
guidata(hObject, 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);
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);
12
139
title('Only Noise Spetrum');
xlabel('Hz');
ylabel('Normalized Magnitude');
grid on;
guidata(hObject, handles);
guidata(hObject, handles);
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
14
141
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
15
142
% Hints: get(hObject,'String') returns contents of editfigureKf as text
% str2double(get(hObject,'String')) returns contents of editfigureKf as a do
16
143
% handles empty - handles not created until after all CreateFcns called
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)
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)
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
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)
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)
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
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;
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);
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');
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');
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)');
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
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;
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);
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');
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
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');
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');
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
[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
*Contact Information*
Email: honglee2335@gmail.com
Phone: 82-10-2301-0626