Creating Sound which changes frequency continuously
7 次查看(过去 30 天)
显示 更早的评论
Hi,
i believe my problem is in fact quite simple to solve, but i am not an expert in sound proccesing/generating. i want to create a beep whose frequency is changing over a specific time, i.e. the * *frequency of the tone should change from 500 Hz to 1000 Hz within the specified time period (i really hope my explanations are understandable...).
as an example this is my code up to now:
a = 1; % amplitude
fs = 8192; % sampling frequency [Hz]
d = 3; % duration of beep [sec]
f_data = 100; % sampling rate of "input" frequency [Hz]
f_range = linspace(500,1000,f_data*d); % starting end ending freq. for the beep
% with 100 datapoints per second
% loop through frequency range
y = [];
for idx = 1:numel(f_range)
tmp_t = 0 : 1/fs : 1/f_data;
tmp_y = a * sin(2*pi * f_range(idx) * tmp_t);
y = [y tmp_y];
end
% play sound
sound(y,fs);
the actual results is somehow weird... there seems to be an overlap of two frequencies: one can hear the increasing frequency, but it is superposed with an much higer frequency resulting in something like a beat frequency.
any idea??
thanks a lot, adam
0 个评论
采纳的回答
Jan
2017-1-24
编辑:Jan
2017-1-25
One single sin() call should be enough, if you transform the time accordingly. For a linear time, the steps between the elements of the vector have the same size. If now the step size is increasing, you get a growing frequency:
duration = 3.0;
fs = 8192;
iniF = 500;
finF = 1000;
A = 1.0; % Amplitude
Now the wave with the inital frequency is:
t = iniF * linspace(0, 3, 3*fs);
y = A .* sin(2 * pi * t);
sound(y, fs);
Equivalently for the final frequency.
Now change the frequencies:
iniStepwidth = iniF / fs;
finStepwidth = finF / fs;
flowStepwidth = linspace(iniStepwidth, finStepwidth, duration * fs);
flowTime = cumsum(flowStepwidth);
y = A .* sin(2 * pi * flowTime);
sound(y, fs);
The frequency information is included in the time vector, which is not linear anymore. Instead of linspace other functions are possible here. I've used ".*" instead of "*" for the amplitude to allow using a vector also e.g. for a increasing volume.
You can see the reason for the artifacts created by your code in the diagram: Run your code, then:
plot(y);
xlim([2000, 2250])
You see, that the single parts do not end at the specified limits of the intervals.
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!