フィルターのクリア

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

15 ビュー (過去 30 日間)
Hans Buchele
Hans Buchele 2021 年 12 月 6 日
編集済み: pluton schmidt 2024 年 6 月 21 日
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!

採用された回答

Star Strider
Star Strider 2021 年 12 月 6 日
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 件のコメント
Star Strider
Star Strider 2021 年 12 月 6 日
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')
.

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

その他の回答 (1 件)

Jon
Jon 2021 年 12 月 6 日
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 件のコメント
Jon
Jon 2021 年 12 月 6 日
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 2024 年 6 月 21 日
編集済み: pluton schmidt 2024 年 6 月 21 日
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.

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

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by