Ask Your Question
1

Low pass filter for coherent demodulation?

asked 10 years ago

mpatton gravatar image

Hello,

I'm trying to design a low-pass filter to recover a signal that was modulated using DSB-SC. I have produced the message signal and the modulated signal, but I can't seem to recover the original.

To modulate, I use a 2 kHz sinusoid: dsb = m(t) * cos(2pi2000t) To begin demodulation, I multiply that signal by another sinusoid of the same frequency: demod = m(t) * cos^2(2pi2000t)

Finally, I (try to) use an FIR low-pass filter with cutoff frequency 100 Hz. Here is what I'm doing:

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt

# Message signal
def message(t):
    m1 = (100*t + 2) * (unit_step(t+0.02) - unit_step(t+0.01))
    m2 = unit_step(t+0.01) - unit_step(t-0.01)
    m3 = (-100*t + 2) * (unit_step(t-0.01) - unit_step(t-0.02))
    return m1 + m2 + m3

T = 1e-4     # sampling interval
fs = 1 / T    # sampling rate
nyq_freq = fs / 2    # Nyquist frequency
fc = 2000    # carrier frequency
B = 100    # using 100 Hz as the bandwidth of the signal m(t)

t = var('t')
dsb = message(t) * cos(2*pi*fc*t)
dem = dsb(t) * cos(2*pi*fc*t)

t = np.arange(-0.04, 0.04, T)    # redefine 't' as an array
m = map(message, t)
dem = map(dem, t)    # make dem into an array representing its values
h = sig.firwin(40, B/nyq_freq)
a = np.ones(len(h))
rec = sig.lfilter(h, a, dem)

plt.plot(t, m, 'b')
plt.plot(t, rec, 'r')

Based on the examples I've seen to implement filters, this looks to be the way it is done? Am I approaching this incorrectly? Ideally, the plots should look quite similar, but these don't.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 10 years ago

mpatton gravatar image

I found my mistake. In the lines

a = np.ones(len(h))
rec = sig.lfilter(h, a, dem)

I should not have passed an array of ones to lfilter(). The correct way to do this turned out to be:

rec = sig.lfilter(h, [1.0], dem)

This gives the correct output. On a side note, since the output of a linear system is effectively the convolution of its input and its unit impulse response, I could have used

rec = sig.convolve(dem, h, mode='same')

I recalled this after struggling with lfilter(). The convolution approach may even be better, because the output of lfilter results in the signal having a phase delay that must be accounted for (this is especially notable when it comes to plotting). convolve() has no such issue.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 1,372 times

Last updated: Mar 20 '15