Borrar filtros
Borrar filtros

How to create a Stereo Sweep from Frequency A to B in a given time?

13 visualizaciones (últimos 30 días)
Dear MathWorks-Community,
I would like to create an audio sweep from frequency A to B in a given time:
For example from 400 to 600 Hertz in 1 second.
Or is it even possible to create an audio sweep from A to B in a given time and then hold this frequency for a given time?
For example from 400 to 600 Hertz in 1 second and the hold 600 Hertz for 9 seconds
Thank you for helping it is much appreciated!

Respuesta aceptada

Star Strider
Star Strider el 6 de Dic. de 2021
The built-in Signal Processing Toolbox chirp function is perfect for this —
Fs = 1E+4;
t1 = linspace(0, Fs-1, Fs)/Fs;
s1 = chirp(t1,400,t1(end),600,'linear'); % Linearly-Increasing Signal
t2 = linspace(t1(end), 9*Fs-1, 9*Fs)/Fs;
s2 = cos(2*pi*600*t2); % Conmstant Signal
t = [t1 t2]; % Concatenate
s = [s1 s2]; % Concatenate
[sp,fp,tp] = pspectrum(s,Fs,'spectrogram','TimeResolution',0.05); % Display Results
figure
mesh(tp,fp,sp)
grid on
xlabel('Time (s)')
ylabel('Frequency (Hz)')
view(60,60)
ylim([0 1000])
To actualy llisten to it —
player = audioplayer(s, Fs);
play(player)
.
  1 comentario
Star Strider
Star Strider el 6 de Dic. de 2021
Following up —
To write a .wav file, use the audiowrite function —
audiowrite('filename.wav', s, Fs)
using the appropriate file name. To save it as a stereophonic file, use ‘smtx’ (see below) instead.
Changing the amplitude requires multiplying it by an appropriate vector with values in the range of ±1. So to create a stereo effect —
inc = linspace(0, 1, numel(s));
dec = linspace(1, 0, numel(s));
smtx = [s(:).*dec(:) s(:).*inc(:)]; % Stereo Matrix [Left Right]
sound(smtx,Fs) % Listening
I cannot hear much of a difference, however the code works in theory —
figure
plot(t, smtx)
grid
xlabel('Time')
ylabel('Amplitude')
legend('Left Channel','Right Channel', 'Location','best')
.

Iniciar sesión para comentar.

Más respuestas (1)

Jon
Jon el 6 de Dic. de 2021
As an alternative, if you don't have the signal processing toolbox, or for some reason preferred to see the details you could do it like this:
% define time and frequency breakpoints
tb = [0 1 9]
fb = [400 600 600]
% compute swept frequency
tFinal = max(tb)
fSample = 10000; % sampling frequency
t = linspace(0,tFinal,fSample*tFinal);
f = interp1(tb,fb,t); % linearly interpolate frequencies to get sweep
% compute output
y = sin(f*2*pi.*t);
% plot result
plot(t,y)
xlabel('time [s]')
ylabel('signal')
  2 comentarios
Jon
Jon el 6 de Dic. de 2021
Note, this is quite general, you could describe any pattern of sweeps and holds using the time and frequency breakpoints tb, and fb
pluton schmidt
pluton schmidt el 21 de Jun. de 2024
Editada: pluton schmidt el 21 de Jun. de 2024
Note that your suggested solution introduces a frequency jump at t=1. This is caused by your definition of the instantaneous frequency which is essentially incorrect, see linear FM.

Iniciar sesión para comentar.

Categorías

Más información sobre Audio Plugin Creation and Hosting en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by