How can I generate audio tone?
이전 댓글 표시
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
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
2020년 4월 3일
Walter Roberson
2020년 4월 3일
That looks pretty good for writing to a file.
However, note this is not "generating" a tone, this is recording something. It is a common homework assignment to be required to generate a tone from a mix of specific frequencies of sine waves.
Osman osmanavci
2020년 4월 3일
Walter Roberson
2020년 4월 3일
What is the waveform of the tone you must generate? The code for generating the tone would be different for a triangle wave than for a sine wave.
Remember, sin(2*pi*Frequency*Time) completes Frequency cycles per second.
Osman osmanavci
2020년 4월 3일
Walter Roberson
2020년 4월 3일
sin(2*pi*Frequency*Time) . Time is 0:number_of_samples divided by sampling frequency.
카테고리
도움말 센터 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
