Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON: Build a DTMF decoder. Your code should accept a tonal sequence and output a string of key presses. Rules: 1. Use a sampling

IN PYTHON:

Build a DTMF decoder. Your code should accept a tonal sequence and output a string of key presses.

Rules:

1. Use a sampling rate of 8000 samples per second.

2. Use a set of bandpass filters, not a FFT.

3. For full credit, use FIR filters of length 31 or less or second order (two pole) IIR filters. You get partial credit for working implementations that use larger filters.

4. You may assume the silence and tonal periods are both multiples of 400 samples. (This is a simplifying assumption.)

5. You may not assume the tones or the silence periods are the same length.

# GIVEN CODE

import numpy as np import matplotlib.pyplot as plt import numpy.random as rnd from IPython.display import Audio %matplotlib inline

# Code below encodes the dialed keypresses

Fs = 8000

#define the keypad and its frequencies validkeys = '*#0123456789ABCD' rowfreqs = [697, 770, 852, 941] colfreqs = [1209, 1336, 1477, 1633] buttons = {'1':(0,0), '2':(0,1), '3':(0,2), 'A':(0,3), '4':(1,0), '5':(1,1), '6':(1,2), 'B':(1,3), '7':(2,0), '8':(2,1), '9':(2,2), 'C':(2,3), '*':(3,0), '0':(3,1), '#':(3,2), 'D':(3,3)}

def dtmf_encoder(phonenumber, dur = 0.5, silencedur=0.1, Fs=8000): """return the DTMF tones for a phone number""" t = np.linspace(0,dur,int(dur*Fs),endpoint=False) silence = np.zeros(int(silencedur*Fs)) sounds = [] for key in phonenumber: if key.upper() in validkeys: r,c = buttons[key] fr, fc = rowfreqs[r], colfreqs[c] #print key, fr, fc sounds.append(np.sin(2*np.pi*fr*t)+np.sin(2*np.pi*fc*t)) sounds.append(silence) return np.concatenate(sounds[:-1]) #drop last silence period

# TESTING CODE FOR ENCODER

test = '123A456B789C*0#D' Audio(dtmf_encoder(test), rate=Fs)

# INSERT YOUR CODE FOR DECODING BELOW

def DTMF_decode(tones): "PUT CODE HERE" pass

# TESTING CODE FOR DECODER (SHOULD OUTPUT TRUE)

def test_dtmfdecoder(dtmfdecoder, dur=0.5, silencedur=0.1, Fs=8000): works = False sigma = 0.0 while sigma < 3.1: number = ''.join([c for c in rnd.permutation(list(validkeys))]) #print number tones = dtmf_encoder(number, dur=dur, silencedur=silencedur) for i in range(5): noisy_tones = tones + sigma*rnd.randn(len(tones)) decoded = dtmfdecoder(noisy_tones) if decoded == number: works = True #print sigma, i else: return works, sigma sigma += 0.1 return works, sigma

test_dtmfdecoder(DTMF_decode) #my solution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago