- A simple way would be to use multiple if-else statements or switch cases within the for loop and execute your statements within these if-else/switch statements
- You could also try the map option in MATLAB
- Use the function pause to produce pauses between every statement execution
- Further, since the first 3 statements for every case (fs, T & t) are the same across all cases, you don't have to write them every time. Having these lines once outside the for loop should suffice
How to play dial tones based on user input?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
My goal is to have dial tones be played for 1 second each with 1 second pauses when the user inputs 10 numbers. I’ve already assigned the tones to variables num1,num2…. I am struggling on how identify the number that is inputted and assign it to the sound and play it with the pauses
clc;clear;
%sound for 1
fs=8192;
T=.5;
t=0:(1/fs):T;
y1=cos(2*pi*1209*t)+cos(2*pi*697*t);
%sound for 2
fs=8192;
T=.5;
t=0:(1/fs):T;
y2=cos(2*pi*1336*t)+cos(2*pi*697*t);
%sound for 3
fs=8192;
T=.5;
t=0:(1/fs):T;
y3=cos(2*pi*1477*t)+cos(2*pi*697*t);
%sound for 4
fs=8192;
T=.5;
t=0:(1/fs):T;
y4=cos(2*pi*1209*t)+cos(2*pi*770*t);
%sound for 5
fs=8192;
T=.5;
t=0:(1/fs):T;
y5=cos(2*pi*1336*t)+cos(2*pi*770*t);
%sound for 6
fs=8192;
T=.5;
t=0:(1/fs):T;
y6=cos(2*pi*1477*t)+cos(2*pi*770*t);
%sound for 7
fs=8192;
T=.5;
t=0:(1/fs):T;
y7=cos(2*pi*1209*t)+cos(2*pi*852*t);
%sound for 8
fs=8192;
T=.5;
t=0:(1/fs):T;
y8=cos(2*pi*1336*t)+cos(2*pi*852*t);
%sound for 9
fs=8192;
T=.5;
t=0:(1/fs):T;
y9=cos(2*pi*1477*t)+cos(2*pi*852*t);
%sound for 0
fs=8192;
T=.5;
t=0:(1/fs):T;
y0=cos(2*pi*1336*t)+cos(2*pi*941*t);
num1=audioplayer(y1,fs);
num2=audioplayer(y2,fs);
num3=audioplayer(y3,fs);
num4=audioplayer(y4,fs);
num5=audioplayer(y5,fs);
num6=audioplayer(y6,fs);
num7=audioplayer(y7,fs);
num8=audioplayer(y8,fs);
num9=audioplayer(y9,fs);
num0=audioplayer(y0,fs);
for ii = 1:10
x(ii) = input('Input a number: ');
end
tt= num2cell(x);
[a,b,c,d,e,f,g,h,i,j] = deal(tt{:});
0 commentaires
Réponses (1)
Vinai Datta Thatiparthi
le 5 Mai 2020
Hey,
A few ideas that could help you:
Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!