MATLAB: output the frequency components of a DTMF signal

AI Thread Summary
The discussion focuses on creating a MATLAB function to output the low and high frequency components of a DTMF signal based on a numeric input (0-9). The user struggles with initializing the variable and implementing the correct control structures, mistakenly using for loops instead of if...elseif statements. The correct approach involves defining the function with input validation and using conditional statements to assign the appropriate frequencies based on the input symbol. Resources for MATLAB documentation are suggested to aid in understanding control logic and function writing. The conversation highlights common pitfalls in MATLAB programming and emphasizes the importance of understanding function parameters and control flow.
makovx
Messages
22
Reaction score
0

Homework Statement



I badly needed an urgent help in Matlab.

I have to create a Matlab function (M-File) that will output the low (flow) and high (fhigh) frequency components of a DTMF signal given the numeric symbol (x) (* and # not included).

I don't even know where to start since this is not discussed. A table is given such that

_______1209 Hz __1336 Hz___1477 Hz
697 Hz____1________2_________3
770 Hz____4________5_________6
852 Hz____7________8_________9
941 Hz____*________0 _________#


Homework Equations



Each pair of tones contains one frequency of the low group (697 Hz, 770 Hz, 852 Hz, 941 Hz) and one frequency of the high group (1209 Hz, 1336 Hz, 1477Hz) and represents a unique symbol. What should I do first?

here's the format..

function [flow fhigh]=mydtmf(x)



The Attempt at a Solution



the output must produce something like this...

[flow fhigh]=mydtmf(1)
flow =
697
fhigh =
1209

>> [flow fhigh]=mydtmf(2)
flow =
697

fhigh =
1336



all help would be deeply appreciated.
 
Physics news on Phys.org
DTMF = dual-tone multifrequence. These are the tones produced by the keys on a telephone keypad.

Given a digit 0, 1, 2, ... , 9, your routine should set flow and fhigh. Probably the simplest but least elegant way to do this is to use brute force with lots of if ... elseif statements.
 
i tried doing the if...for... else..elseif statements but I still can't do it right.
I mean for me to write a function, I have to write something like this

function [flow fhigh]= mydtmf (x)

wherein x is the number 0 to 9.

but it says that variable x is not initialized. what does it mean?
how to initialize the variable x?
 
It means that the parameter x in your function doesn't have a value yet. Before you call your function you have to give x a value, most likely by input from the keyboard. It's sort of like me asking you to tell me the square root of a number without first telling you the number.
 
function [flow fhigh]= mydtmf(x)
x = input('number from 0-9: ')
if x>=0 & x<=9
[flow fhigh]= mydtmf(x)

for x==1,
disp('flow = 697 Hz')
disp('fhigh = 1209 Hz')
end

for x==2,

disp('flow = 697 Hz')
disp('fhigh = 1336 Hz')
end

for x==3,

disp('flow = 697 Hz')
disp('fhigh =1477 Hz')
end

for x==4,

disp('flow = 770 Hz')
disp('fhigh = 1209 Hz')
end

for x==5,

disp('flow = 770 Hz')
disp('fhigh = 1336 Hz')
end

for x==6,

disp('flow = 770 Hz')
disp('fhigh = 1477 Hz')
end

for x==7,

disp('flow = 852 Hz')
disp('fhigh = 1209 Hz')
end

for x==8,

disp('flow = 852 Hz')
disp('fhigh = 1336 Hz')
end

for x==9,

disp('flow = 852 Hz')
disp('fhigh = 1477 Hz')
end

for x==0,

disp('flow = 941 Hz')
disp('fhigh = 1336 Hz')
end
end

this is my syntax. but when i tried to rum it, here's what I've got...

?? Error: File: D:\matlab7\mydtmf.m Line: 6 Column: 10
Missing variable or function.

Line:6 Column 10 is the part of

for x==1
 
You are (incorrectly) attempting to use for loops when you don't want any loops at all. What you want instead are are series of if ... elseif statements. If you don't have any documentation, here is a link to some that might be helpful -- http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf. Chapter 4 has information about control logic (including if statements and for loops) and how to write functions.
 
Back
Top