How can I generate audio tone?

139 次查看(过去 30 天)
How can I generate 10kHz,5 second audio tone and it`s sampling frequency is equal to 44100 Hz? and How can I set the magnitude?

回答(1 个)

Walter Roberson
Walter Roberson 2020-4-2
编辑:Walter Roberson 2020-4-3
Create a vector of samples that is ((sampling frequency) times (number of seconds)) long. Then you can play it with audioplayer() or sound() .
When you use audioplayer() or sound(), what you would pass to it would typically be floating point data in the range -1 to +1 . That range of values corresponds to (potentially) full volume, according to whatever amplification is being done by devices that are (mostly) outside the control of MATLAB. (In some cases there are calls you can make to change the volume setting of your operating system.) Aside from amplification questions, the volume percieved by the user is going to relate to the range of motion: if you were to send data in the range 0 to +1 only, then the effect on loudness would be the same as if you were to send -1 to 0, and that in turn would be the same as if you sent -1/2 to +1/2; all three are half of the volume that could be achieved. The values you send are not directly volume numbers: they are how far in or out the speaker cone is to be from relaxed, and volume comes with motion, not with pure extension. sound(ones(14000), 4000) would be silent because there is no motion.
So, if you have a set of samples centered around 0, and you want to play it at (say) 25% of the maximum the hardware is configured for, then multiply the samples by 25%.
s=rand(1,4000);
sound(s,4000);
sound(s*0.25,4000)
  6 个评论
Osman osmanavci
Osman osmanavci 2020-4-3
it can be sine form, I am going to use to design a filter to obtain original recording voice from distorted audio signal.
Walter Roberson
Walter Roberson 2020-4-3
sin(2*pi*Frequency*Time) . Time is 0:number_of_samples divided by sampling frequency.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by