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?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 14일

4 개 추천

You can use sound function

댓글 수: 7

ramdas patil
ramdas patil 2014년 6월 14일
@ Azzi Abdelmalek sir i used sound function,but i am unable to play sound for given interval of time as specified above.can u send me code for above?
Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 14일
편집: Azzi Abdelmalek 2014년 6월 14일
amp=10
fs=20500 % sampling frequency
duration=10
freq=100
values=0:1/fs:duration;
a=amp*sin(2*pi* freq*values)
sound(a)
Image Analyst
Image Analyst 2014년 6월 14일
ramdas, it was tagged as homework. If it's homework you can't just ask someone to do it all for you. If it's not homework, say so.
ramdas patil
ramdas patil 2014년 6월 14일
@Image Analyst Sir it is not homework.i wanted to check fourier spectrum.i dont know how it was like that.
Yonas Gedamu
Yonas Gedamu 2021년 2월 8일
how to get amplitude. amplitude is not given? could you help me?
Image Analyst
Image Analyst 2021년 2월 8일
@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.
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 6월 14일

4 개 추천

See my attached demo that creates a sound and plays it.

댓글 수: 5

Image Analyst
Image Analyst 2014년 6월 14일
Have you tried to use the fft() function on the signal?
ramdas patil
ramdas patil 2014년 6월 14일
@Image Analyst yes sir i used fftn function.but i was getting error in the generation of two given signals for 10 sec and 5 sec respectively.
Image Analyst
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.
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)
@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
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
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
zina shadidi 2019년 5월 22일
sorry Image Analyst
I can not find it or any comments
Image Analyst
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에 대해 자세히 알아보기

질문:

2014년 6월 14일

댓글:

2021년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by