フィルターのクリア

Creating Sound which changes frequency continuously

9 ビュー (過去 30 日間)
Adam Zabicki
Adam Zabicki 2017 年 1 月 24 日
コメント済み: Adam Zabicki 2017 年 1 月 25 日
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

採用された回答

Jan
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 件のコメント
Jan
Jan 2017 年 1 月 25 日
編集済み: Jan 2017 年 1 月 25 日
@Adam: Sound - to "visualize" an angle?!! Wow. I'm interested. I contact you by email.
Adam Zabicki
Adam Zabicki 2017 年 1 月 25 日
ok :)
and despite the long day i just solved the problem. first calculate the duration
duration = numel(angle) / angle_fs;
than calculate how much time steps are needed
fs_dur = fs*duration;
and then use interp1 for linear interpolation (linear is not "perfect", but in that time dimensions it shouldn't matter)
angle_interp = interp1(1:numel(angle),angle,linspace(1,numel(angle),fs_dur));
continued like described above
angle_scaled = (angle_interp - min(angle_interp)) * (finF - iniF) / (max(angle_interp) - min(angle_interp)) + iniF;
% create sound
flowSteps = angle_scaled / fs;
flowTime = cumsum(flowSteps);
y = A .* sin(2 * pi * flowTime);
sound(y, fs);
done :) thanks again for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by