Having issues playing a simple tone with MATLAB.
이전 댓글 표시
Here is my function:
function playtone(freq,sf,amplitude,duration)
%Plays a simple tone.
%freq = frequency of tone (in Hz).
%sf = sampling frequency (in Hz).
%amplitude = sound amplitude (dimensionless).
%duration = sound duration (in seconds).
t = 0:1/sf:duration;
sound_vector = amplitude*sin(2*pi*freq*t);
sound(sound_vector,sf)
.
.
.
.
.
.
.
.
.
Here are my values:
>> freq = 1000;
>> sf = 10000;
>> amplitude = 1;
>> duration = 10;
답변 (1개)
Image Analyst
2016년 11월 21일
0 개 추천
It works fine for me. Make sure your speakers are turned on, both on your computer, and on the speakers themselves.
댓글 수: 5
Carlyle Hickman
2016년 11월 21일
Image Analyst
2016년 11월 21일
Here is the complete code, all in test2.m:
function test2
% Here are my values:
freq = 1000;
sf = 10000;
amplitude = 1;
duration = 10;
playtone(freq, sf, amplitude, duration);
helpdlg('Done!');
function playtone(freq,sf,amplitude,duration)
%Plays a simple tone.
%freq = frequency of tone (in Hz).
%sf = sampling frequency (in Hz).
%amplitude = sound amplitude (dimensionless).
%duration = sound duration (in seconds).
t = 0: 1/sf: duration;
sound_vector = amplitude * sin(2*pi*freq*t);
sound(sound_vector,sf)
I'm also attaching the m-file.
Carlyle Hickman
2016년 11월 21일
Image Analyst
2016년 11월 21일
Did you save it as test2.m like I had it? If so, it should run. You must have changed the name of it when you saved it. Please attach your m-file with the paper clip icon.
Carlyle Hickman
2016년 11월 21일
카테고리
도움말 센터 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!