how do i generate sound using MATLAB?

82 Ansichten (letzte 30 Tage)
ramdas patil
ramdas patil am 14 Jun. 2014
Kommentiert: Image Analyst am 17 Feb. 2021
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?

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 14 Jun. 2014
You can use sound function
  7 Kommentare
Image Analyst
Image Analyst am 8 Feb. 2021
@Yonas Gedamu, Start a new question after you read this:
Then we'll know how to answer you precisely. Right now you have not given enough information. Not given from where? Who told you to do this? Amplitude in the spectral domain or the time domain, etc. I should know how to help you after you provide us the context - background information and any data you already have.
Adam Danz
Adam Danz am 17 Feb. 2021
Small correction from Azzi's comment,
sound(a)
should be
sound(a,fs)
I don't have access to the 2014 documentation so I don't know what the inputs were for this function back then.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 14 Jun. 2014
See my attached demo that creates a sound and plays it.
  5 Kommentare
Bow
Bow am 31 Mär. 2018
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
Image Analyst am 17 Feb. 2021
@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.

Melden Sie sich an, um zu kommentieren.


zina shadidi
zina shadidi am 22 Mai 2019
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 Kommentare
zina shadidi
zina shadidi am 22 Mai 2019
sorry Image Analyst
I can not find it or any comments
Image Analyst
Image Analyst am 23 Mai 2019
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by