How to create a Stereo Sweep from Frequency A to B in a given time?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hans Buchele
am 6 Dez. 2021
Bearbeitet: pluton schmidt
am 21 Jun. 2024
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!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 6 Dez. 2021
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 Kommentar
Star Strider
am 6 Dez. 2021
Following up —
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')
.
Weitere Antworten (1)
Jon
am 6 Dez. 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 Kommentare
Jon
am 6 Dez. 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
am 21 Jun. 2024
Bearbeitet: pluton schmidt
am 21 Jun. 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.
Siehe auch
Kategorien
Mehr zu Audio Plugin Creation and Hosting finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!