Вы находитесь на странице: 1из 22

Lab 5

le:///home/aman/Dropbox/Lab 5.html

EECS 3451
Lab 05: Amplitude Modulation
Submitted by: Amanpreet Walia
Student No. : 212938734
Submitted on: November 29, 2015

Introduction
The basic idea behind the given lab is to explore the use of digital computers for the analysis, design, synthesis, and
simulation of an amplitude modulation (AM) system using Python where an information signal is multiplied by a sinusoid at a
much higher frequency.The phenomenon of modulation, its impact on the signal spectrum and how this is used to simulate
the modulation and demodulation of an audio signal. The main topics to be dealt in this labortary is frequency
shifting,amplitude modulation,demodulation,sampling,aliasing and Digital Fourier analysis. This forms the major objective of
the lab is to compute, display, and interpret frequency spectra of an amplitude modulated signal.Design and use digital filters
to prevent aliasing in your computer simulation of an AM system.Use your understanding of frequency-domain analysis and
digital filters to design and build a system for modulating and demodulating audio signals,prevent aliasing by using filters or by
changing the sampling rate.This lab is basically divided into two segments : Software Experiment and Hardware Experiment.
The hardware experiment requires us to use the envelope detection circuit to demodulate the modulated signal and obtain the
original signal.

Preparation
Question 1
Assume that the given signal tone is Acos(2 100t). We have to take modulating/carrier signal to be 2cos(2 250t) and then
apply low pass filter with cutoff frequency of 170 Hz to obtain tone of 150 Hz.

modulated signal = A cos(2 100t) 2 cos(2 250t)


modulated signal = A(cos(2 150t) + cos(2 350t))

After this applying Low pass filter to modulated signal with cutoff frequency of 170 Hz we can block the high pass component
to obtain the desired signal

1 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [108]: import numpy as np


from scipy.signal import butter, lfilter, freqz
import matplotlib.pyplot as plt
def lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return b, a
def lowpass_filter(data, cutoff, fs, order=5):
b, a = lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
# Filter requirements.
order = 10
fs = 4000
cutoff = 175 # desired cutoff frequency of the filter, Hz
# Get the filter coefficients so we can check its frequency response.
b, a = lowpass(cutoff, fs, order)
# Plot the frequency response.
w, h = freqz(b, a, worN=8000)
plt.figure(figsize=(16, 12))
plt.subplot(5, 1, 1)
plt.plot(0.5*fs*w/np.pi, np.abs(h), 'b')
plt.plot(cutoff, 0.5*np.sqrt(2), 'ko')
plt.axvline(cutoff, color='k')
plt.xlim(0, 0.5*fs)
plt.title("Lowpass Filter Frequency Response")
plt.xlabel('Frequency [Hz]')
plt.grid()
# Demonstrate the use of the filter.
# First make some data to be filtered.
T = 0.1
# seconds
n = int(T * fs) # total number of samples
t = np.linspace(0, T, n, endpoint=False)
# "Noisy" data. We want to recover the 1.2 Hz signal from this.
signal = np.cos(100*2*np.pi*t)
carrier = np.cos(250*2*np.pi*t)
modulted_sig = (signal)*carrier
# Filter the data, and plot both the original and filtered signals.
y = lowpass_filter(modulted_sig, cutoff, fs, order)
plt.subplot(5, 1, 2)
plt.plot(t, signal,'b-',label='150 Hz Tone')
plt.subplot(5, 1, 3)
plt.plot(t,carrier, 'g-',label='Carrier')
plt.subplot(5, 1, 4)
plt.plot(t,modulted_sig, label='Modulated Signal')
plt.subplot(5, 1, 5)
plt.plot(t,y, label='filtered signal')
plt.xlabel('Time [sec]')
plt.grid()

2 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Question 2
Here the minimum frequency at which signal can be sampled is 200 Hz.

3 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

We have to use Low pass Filter with unity gain and cutoff frequency between 100 to 300 Hz to obtain the original signal back.

Question 3

4 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Minimum Frequency at which signal is 2.2KHz.

5 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Yes Aliasing will occur as the resulting spectrum will coincide with each other.This is because by using 2 kHz sampling
frequency we are have original spectrum occuring at intervals of 2 Khz period but original spectrum have bandwidth due to
which they coincide with each other.

Question 4

6 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Here we use low pass filter with magnitude of e2f0.1

Procedure and Result


This lab is divide into two parts : Software and hardware analysis of Amplitude modulation.We use different techniques for
analysis.

7 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Problem 1
In this Problem we studied the frequency spectrum of amplitude modulated signal after doing amplitude modulation on cosine
wave.

8 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [113]: import matplotlib.pyplot as plt


import numpy as np
import scipy.io.wavfile as wav
%matplotlib inline
rate = 8000
Ts = 1/rate
fc = 1000
t = np.arange(0,4,Ts)
x = 5 + np.cos(110*np.pi*t)
y = (1+x)*np.cos(2*np.pi*fc*t)
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(16, 10))
axes[0].plot(t,x)
axes[0].set_xlim([0., 0.1])
axes[0].set_ylim([3, 7])
axes[0].set_xlabel('time')
axes[0].set_ylabel('Amplitude')
axes[0].set_title('Signal')
axes[1].plot(t,y)
axes[1].set_xlim([0., 0.1])
axes[1].set_ylim([-7, 7])
axes[1].set_xlabel('time')
axes[1].set_ylabel('Amplitude')
axes[1].set_title('Modulated wave')
plt.figure(figsize=(16,8))
plt.plot(np.fft.fftfreq(y.size, d=1/rate),np.abs(np.fft.fft(y)/(rate*max(t))),
label='Frequency Spectrum')
plt.show()
w1 = x.astype(np.int16)
w2 = y.astype(np.int16)
wav.write('modulated.wav',rate,w2)
wav.write('signal.wav',rate,w1)

9 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Problem 2

10 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [114]: import matplotlib.pyplot as plt


from scipy.io import wavfile as wav
rate, data = wav.read('P_12_1.WAV')
%matplotlib inline
plt.figure(figsize=(16.0,8.0))
plt.plot(data[:1500])
plt.title('Speech Signal')
plt.ylabel('Amplitude(Voltage)')
plt.xlabel('Time(t)')
plt.show()

In [115]: plt.figure(figsize=(16,8))
plt.plot(np.fft.fftfreq(data.size, d=1/rate),np.abs(np.fft.fft(data)/(rate*max
(t))), label='Frequency Spectrum')
plt.show()

11 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [116]: fc = 8000
t = np.arange(0,((data.shape[0])/rate),1/rate)
xc = (1+0.5*data)*np.cos(2*np.pi*fc*t)
plt.figure(figsize=(16.0,8.0))
plt.plot(xc[:1500])
#plt.xlim([0., xc.shape[0]])
plt.title('Modulated Speech Signal')
plt.ylabel('Amplitude(Voltage)')
plt.xlabel('Time(t)')
plt.show()
w3 = xc.astype(np.int16)
wav.write('modulated speech.wav',rate,w3)

In [117]: plt.figure(figsize=(16,8))
plt.plot(np.fft.fftfreq(xc.size, d=1/rate),np.abs(np.fft.fft(xc)/(rate*max(t))
), label='Frequency Spectrum')
plt.show()

12 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Problem 3

13 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [118]: import numpy as np


from scipy.signal import butter, lfilter, freqz
import matplotlib.pyplot as plt
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return 2*b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
# Filter requirements.
order = 10
fs = 8000
# sample rate, Hz
cutoff = 100 # desired cutoff frequency of the filter, Hz
# Get the filter coefficients so we can check its frequency response.
b, a = butter_lowpass(cutoff, fs, order)
# Plot the frequency response.
w, h = freqz(b, a, worN=8000)
plt.figure(figsize=(20.0,20.0))
plt.subplot(3, 1, 1)
plt.plot(0.5*fs*w/np.pi, np.abs(h), 'b')
plt.plot(cutoff, 0.5*np.sqrt(2), 'ko')
plt.axvline(cutoff, color='k')
plt.xlim(0, 0.5*fs)
plt.title("Lowpass Filter Frequency Response")
plt.xlabel('Frequency [Hz]')
plt.grid()
# Demonstrate the use of the filter.
# First make some data to be filtered.
T = 4.0
# seconds
n = int(T * fs) # total number of samples
t = np.linspace(0, T, n, endpoint=False)
# "Noisy" data. We want to recover the 1.2 Hz signal from this.
fc = 1000
x = 5 + np.cos(110*np.pi*t)
mod_data = (1+x)*np.cos(2*np.pi*fc*t)
# Filter the data, and plot both the original and filtered signals.
data = mod_data *np.cos(2*np.pi*fc*t)
y = butter_lowpass_filter(data, cutoff, fs, order)
plt.subplot(3, 1, 3)
plt.plot(t[:1500], y[:1500], 'g-', linewidth=2, label='filtered data')
plt.ylim([5,7])
plt.xlabel('Time [sec]')
plt.grid()
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(t[:1500], x[:1500], 'r-', linewidth=2, label='Actual data')
plt.xlabel('Time [sec]')

14 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

Problem 4

15 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [119]: import matplotlib.pyplot as plt


from scipy.io import wavfile as wav
rate4, p4 = wav.read('/home/aman/Dropbox/P_12_2.WAV')
plt.figure(figsize=(16.0,8.0))
plt.plot(p4)
plt.title('P_12_2 Signal')
plt.ylabel('Amplitude(Voltage)')
plt.xlabel('Time(t)')
plt.figure(figsize=(16,8))
plt.plot(np.fft.fftfreq(p4.size, d=1/rate4),np.abs(np.fft.fft(p4)/(rate4*max(t
))), label='Frequency Spectrum')
plt.show()

Here the carrier frequency is obtained from the frequency spectrum of the signal as 16000 Hz and bandwidth as 3000 Hz.

16 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [126]: import matplotlib.pyplot as plt


from scipy.io import wavfile as wav
import numpy as np
from scipy.signal import butter, lfilter, freqz
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return 2*b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
# Filter requirements.
rate4, p4 = wav.read('/home/aman/Dropbox/P_12_2.WAV')
order = 10
fs = rate4
# sample rate, Hz
cutoff = 5000 # desired cutoff frequency of the filter, Hz
# Get the filter coefficients so we can check its frequency response.
b, a = butter_lowpass(cutoff, fs, order)
# Plot the frequency response.
w, h = freqz(b, a, worN=8000)
plt.figure(figsize=(20.0,20.0))
plt.subplot(3, 1, 1)
plt.plot(0.5*fs*w/np.pi, np.abs(h), 'b')
plt.plot(cutoff, 0.5*np.sqrt(2), 'ko')
plt.axvline(cutoff, color='k')
plt.xlim(0, 0.5*fs)
plt.title("Lowpass Filter Frequency Response")
plt.xlabel('Frequency [Hz]')
plt.grid()
N = p4.shape[0]
f_c =16000
Ts = 1/fs
T = N*Ts
t = np.arange(0,T-1/N,Ts)
data = p4*np.cos(2*np.pi*f_c*t)
y = butter_lowpass_filter(data, cutoff, fs, order)
plt.subplot(3, 1, 2)
plt.plot(t, p4, 'r-', linewidth=2, label='Actual data')
plt.xlabel('Time [sec]')
plt.grid()
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t, y, 'g-', linewidth=2, label='filtered data')
#plt.ylim([15000,20000])
plt.xlabel('Time [sec]')
plt.grid()
plt.legend()

17 of 22

2015-11-30 12:53 AM

Lab 5

18 of 22

le:///home/aman/Dropbox/Lab 5.html

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In [127]: plt.figure(figsize=(16,8))
plt.plot(np.fft.fftfreq(y.size, d=1/rate4),np.abs(np.fft.fft(y)/(rate4)), labe
l='Frequency Spectrum')
plt.show()

In [128]: w4 = y.astype(np.int16)
wav.write('p4.wav',rate,w4)

With these modifications wave form was clearly heard hence being correctly demodulated.

Problem 5

19 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

We Obtain the following output from the osciloscope for amplitude modulation.

Problem 6

20 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

We use this circuit to obtain the required envelope to obtain the signal from the modulated wave

Since the equipment was not available in the lab,its only possible to obtain the waveform using simulation.

We obtain this waveform

Discussion

21 of 22

2015-11-30 12:53 AM

Lab 5

le:///home/aman/Dropbox/Lab 5.html

In this lab we studied about amplitude modulation of signal and how modulation and demodulation can be actually
implemented.We studied the modulation technique in both frequency as well as time domain.While domain serve as actual
physical representation of the signal, analysis in frequency domain serve as more important tool to analysze the signals.We
used Fourier analysis to analyze the signals for determing their frequency spectrum.We analysed how sampling frequency is
closely related to frequency of signal and how signal is effected if it is sampled at frequency lower than the minimum
frequency.Amplitude demodulation can be realised by either using filter or analog circuit technique.We implemented Filter
demodulation on software whereas envelope dtection using analog circuit is done with the help of circuit board and
osciloscope to view the result.

Conclusion
All the software as well as hardware analysis done in the lab was succesful.We used scipy and numpy toolbox to analyze
signals in frequency and time domain and circuit board realised on breadboard to analyze signal for hardware analysis.The
hardware part of the lab is done with envelope detection circuit which is made up of diode, capacitor and resistors.The
envelope detection circuit can operate as long as the carrier frequency is much higher than the highest frequency present in
the signal.The waveform obtained after demodulation was analyzed which happens to be bit choppy as compared to the
original input.The software aspect basically deals with modulation and demodulation using the phenomenon of frequency
shifting, aliasing, sampling , the concept of filters was understood and used to complete the given tasks.We obtained
fundamental understanding of amplitude modulation while doing the las through the wave files and frequency spectrums.
In [ ]:

22 of 22

2015-11-30 12:53 AM

Вам также может понравиться