Need help about function
1 次查看(过去 30 天)
显示 更早的评论
I have written this function for piano
function tone=note(keynum,dur) % %This function produces sinusoidal waveform corresponding to given piano %key number %tone=output sinusoidal waveform %keynum= The piano keyboard number %dur= The duration in seconds of output note fs=8000; tt=0:(1/fs):dur; freq = 440 (2^((keynum-49)/12)); tone=sin(2*pi*freq(0:0.000125:1));
Now If i use soundsc(tone,fs) command in the code of this function then every thing is ok but the book says
"You can play the output of this function using the soundsc() function in Matlab. DO NOTcall the sound fucntion within the M-file.
Plz help me how to go about this. when i write note(12,3) in matlab it is ok but when i write soundsc(tone,fs) in matlab after this it gives error
0 个评论
采纳的回答
Wayne King
2011-9-19
How are you calling the function, note(), at the command line?
You should call it as:
tone = note(12,3);
Then there will be a variable in your workspace named tone and you can execute
soundsc(tone,fs)
If you call it as
note(12,3)
then your output appears as ans
Wayne
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!