How to create siren sound using makesound
14 次查看(过去 30 天)
显示 更早的评论
Dear all,
I am trying to generate sound which follows an amplitude signal. Means, when amplitude of my signal is increasing, my frequency is too, etc ..
To start as simple, I made different consecutive sounds with different frequencies to first understand the principle, playing well. Then increased the complexity by generating a vector which represents the frequency variation of my sound. I did it as sinusoidal, should sound like a siren.
Then using this variable frequency vector, I generate the sound using the sound function. At the end, I can hear the frequency varying but also constantly increasing and I don't understand why. Could you please tell me what is wrong here ? I am pretty sure I'm facing very basic misunderstanding ...
Thank you in advance !
% create the frequency oscillation "siren" frequency, between 200 and 400Hz, oscillating at 1Hz.
time = 0:0.001:5;
f = 100*sin(2*pi*1*time) + 300;
fs=44100; % sample rate
% setup the nb of points according to time length of the signal and sample
% rate
d=time(end); %duration
n=fs*d; % number of points
t=(1:n)/fs;
% Interp the previous frequency vector to fit the new time vector
f = interp1(time,f,t);
% Generate the signal
y=sin(2*pi*f.*t);
sound(y,fs);
0 个评论
采纳的回答
Mathieu NOE
2021-2-1
hello
You have to remember that the output is the sinus of an angle, which is the integral of frequency over time;
so when frequency also varies with time , it's incorrect to simply make the product of 2*pi*f*t, you have to do the integral with cumtrapz as shown below :
I also simplified a bit your code (only one time vector needed)
fs=44100; % sample rate
dt = 1/fs;
t = 0:dt:5;
f = 100*sin(2*pi*1*t) + 300;
% Generate the signal
angl = cumtrapz(t,f); % angle is integral of frequency
y=sin(2*pi*angl);
sound(y,fs);
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!