Ask Your Question

mpatton's profile - activity

2017-06-07 11:08:10 +0200 received badge  Famous Question (source)
2016-10-20 07:08:24 +0200 received badge  Notable Question (source)
2015-10-30 18:19:54 +0200 received badge  Popular Question (source)
2015-04-01 04:06:11 +0200 received badge  Supporter (source)
2015-03-24 11:38:41 +0200 received badge  Self-Learner (source)
2015-03-24 11:38:41 +0200 received badge  Teacher (source)
2015-03-24 11:38:19 +0200 received badge  Student (source)
2015-03-20 21:17:18 +0200 answered a question Low pass filter for coherent demodulation?

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.

2015-03-19 16:12:23 +0200 asked a question Low pass filter for coherent demodulation?

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.

2014-11-24 02:49:02 +0200 received badge  Scholar (source)
2014-11-24 02:34:40 +0200 commented answer Condition in sum() function?

This is precisely what I was looking for. I didn't even think to use n as a Python variable. Thank you sir.

2014-11-24 02:29:57 +0200 commented question Condition in sum() function?

Yes, I only want to avoid n = 0. Thank you for your input, I ended up using the answer below.

2014-11-22 19:52:33 +0200 received badge  Organizer (source)
2014-11-22 19:50:08 +0200 asked a question Condition in sum() function?

Hello,

I'm trying to use the exponential form of the Fourier series representation of a function to plot an approximation of said function using the first five terms.

The actual function is f(t) = 1/2 + j/(2pi) * E from (n = -5) to (n = 5) of ((-1)^n - 1)/n * e^(j2npi*t), where n =/= 0

Here I'm using 'E' to indicate summation notation. I apologize if this deviates from an established standard, but I'm having trouble uploading images right now (which would have made the function clearer).

The code I'm using for this function is

var('n, t')
j = i    # imaginary unit
expr = ((-1)^n - 1)/n * exp(2*pi*n*j*t)    # I think the problem is the division by 'n' here
assume(n, 'integer'); assume(n != 0)
f(t) = 1/2 + j/(2*pi) * sum(expr, n, -5, 5)

However, when I try this, I get the following exception:

RuntimeError: ECL says: Error executing code in Maxima: expt: undefined: 0 to a negative exponent.

This seems to be due to the division by n in expr. Are my assumptions not working here? Thus, my actual question is how can I add the condition n != 0 to the sum() function in sage?