how do i generate sound using MATLAB?
古いコメントを表示
I want to generate and play *sound for frequencies 100Hz and 200Hz tones for 10 sec and 5 sec respectively using MATLAB With sampling frequency as 20500 Hz .Also i want to plot their frequecy spectrum* .Is it possible to do this using MATLAB?
採用された回答
その他の回答 (2 件)
Image Analyst
2014 年 6 月 14 日
4 投票
See my attached demo that creates a sound and plays it.

5 件のコメント
Image Analyst
2014 年 6 月 14 日
Have you tried to use the fft() function on the signal?
ramdas patil
2014 年 6 月 14 日
Image Analyst
2014 年 6 月 14 日
Just getting back, and I noticed you accepted Azzi's answer so I assume that this question is not applicable anymore. Glad everything is working.
Bow
2018 年 3 月 31 日
Adding a small correction to the answer above. You should include fs as an argument into the sound function if you want it to play correctly. If you don't MATLAB will use the default sampling freqeuncy, which is not 20500Hz. So the last line should be
sound(a,fs)
Image Analyst
2021 年 2 月 17 日
@Bow, I don't think you were talking about my code. My code did/does use Fs and doesn't call the signal "a". (I downloaded it to check.) Regardless, I'm attaching the latest version which uses the new sound function "audioplayer()":
player = audioplayer(y, Fs);
play(player);
I'd advise anyone to use this version (attached to this comment) instead of the original version of the m-file attached to my original 6 year old answer.
zina shadidi
2019 年 5 月 22 日
0 投票
can I use your demo??
If you agree , I want to ask you to explain it to me please
best regards
Zina Al Shadidi
3 件のコメント
Image Analyst
2019 年 5 月 22 日
Yes, you can use it. The explanations are in the comments. The code is well and heavily commented.
zina shadidi
2019 年 5 月 22 日
sorry Image Analyst
I can not find it or any comments
Image Analyst
2019 年 5 月 23 日
It's attached to my answer. I'm attaching it again here.
Open the code in MATLAB and you'll see many, many lines with a % on them (indicating comments). The comments will also be color coded in green. If you have any questions not explained well by the existing comments, write back to tell me what chunk of code is not well explained/commented.
カテゴリ
ヘルプ センター および File Exchange で Signal Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!