Creating a sound with certain obtained frequencies
27 ビュー (過去 30 日間)
古いコメントを表示
I am trying to create a new sound with certain frequencies I found using the pitch function. I gathered the frequencies into one vector (f0). I based my code on this particular question: https://www.mathworks.com/matlabcentral/answers/519684-generate-sound-with-specific-frequencies but every time I run the code, it says that there is an error using sound (Only one and two channel audio supported). Is there anyway I could fix this? Also, if there is any other way I could produce a sound with specific frequencies, please let me know too. I am currently aware of the chirp function, but also having a difficult time with that too. Thank you!
amp = 0.5;
Fs = sum(f0, 'all');
Ts = 1/Fs;
T = 0:Ts:1; %play each frequncy for 1 second
x = [];
for freq = f0
x = [ x amp * sin(2*pi*freq*T)];
end
sound(x,Fs)
0 件のコメント
回答 (1 件)
Les Beckham
2021 年 7 月 22 日
編集済み: Les Beckham
2021 年 7 月 22 日
Try this. Since you didn't provide f0 in your example code, I just picked some frequencies. Also, I changed to a fixed output frequency. I'm not sure what you meant to do with the calculation of the sampling frequency as a sum of the output frequencies.
% answers_88349.m
%
% https://www.mathworks.com/matlabcentral/answers/883449-creating-a-sound-with-certain-obtained-frequencies?s_tid=srchtitle
f0 = [4000 6000 8000]; % not provided in question code
amp = 0.5;
% Fs = sum(f0, 'all');
Fs = 41000; % Better (I think) to use a fixed frequency.
Ts = 1/Fs;
T = 0:Ts:1; %play each frequency for 1 second
x = [];
for freq = f0
x = [ x, amp * sin(2*pi*freq*T)];
end
sound(x,Fs)
I'm not sure how this addresses the error you say you are getting, but this works for me. Since you didn't provide a full (not working) example, or provide the full text of your error message, it is difficult to know more about what was going on.
However, this code works for me.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!