Creating Sound which changes frequency continuously
7 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan
on 24 Jan 2017
Edited: Jan
on 25 Jan 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!