How can I properly decode the signal I am coding?
Show older comments
This is the assignment I was given:
_Develop your own coder and decoder to send a message to a friend and protect the context of your message from those who might be able to intercept your message signal.
You should write a program that can send all capital and lower characters from A-Z, a-z, plus period (.), comma (,), and space.
The requirements: 1. The program should request an input from the keyboard. The input should be a single character. Once, the input is received your program should code the character and display the code signal on the screen. 2. Then your program should decode the signal and display the character on the screen. 3. You should have a loop in your program, so that the steps 1 and 2 could be repeated until the message is completed and the character (!) is inputed which implies the communication is over. _
Below is the code I have developed. I am able to code a message successfully but I am unsure how to decode it as required in step two. Should there be another outer loop that encompasses both the coder and decoder? Should the decoder be done after each coding part? How do I display the characters again? Help? :/
% Objective: Send secret code using dual-tone multi-frequency signaling
%Coder
for i=1:281474976710655
character = input('Please enter a letter, a comma, a period or a space [Enter ! when done]: ');
if character == 'A';
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'B'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'C'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'D'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'E'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'F'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'G'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(697)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'H'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'I'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'J'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'K'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'L'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'M'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'N'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(770)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'O'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'P'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'Q'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'R'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'S'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'T'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'U'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(852)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'V'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'W'
z=[0:1:5000];
x=sin(2*pi*(1366)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'X'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'Y'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'Z'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'a'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'b'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(941)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'c'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'd'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'e'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'f'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'g'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'h'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'i'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(1035)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'j'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'k'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'l'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'm'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'n'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'o'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'p'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(1132)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'q'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'r'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 's'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 't'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'u'
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'v'
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'w'
z=[0:1:5000];
x=sin(2*pi*(2201)*(z/5000));
y=sin(2*pi*(1230)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'x'
z=[0:1:5000];
x=sin(2*pi*(1209)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'y'
z=[0:1:5000];
x=sin(2*pi*(1336)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == 'z'
z=[0:1:5000];
x=sin(2*pi*(1477)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == '.'
z=[0:1:5000];
x=sin(2*pi*(1633)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == ','
z=[0:1:5000];
x=sin(2*pi*(1805)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == ' '
z=[0:1:5000];
x=sin(2*pi*(1994)*(z/5000));
y=sin(2*pi*(1329)*(z/5000));
c=x+y;
figure(i);
plot(c);
else if character == '!'
break
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
%Decoder
[Pxx,f]=pwelch(c,[],[],[],5000);
figure(i);
plot(f,Pxx);
1 Comment
Walter Roberson
on 10 Feb 2013
If you look around here, you will find postings on "decode dtmf".
Suggestion: With the steps of your encoding being the same for each character, with just the frequencies being different, you should consider having your if-else chain just set the frequency values to use, and then do all the actual construction after the loop.
You should also review "elseif" and "switch"
Answers (0)
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!