【发布时间】:2016-09-22 16:16:52
【问题描述】:
我想通过 MATLAB 生成声音,该声音由预定义数量的不同频率滑移(扫描)组成。为此我写了一段MATLAB代码。但是,我遇到了两个问题:
1) 当我播放声音时,声音会在整个播放期间发出咔哒声。
-> 这可能与前一个扫描段的结尾和下一个扫描段的开头不同的相位角有关。我试图解决这个问题(请参阅下面的代码) - 到目前为止没有成功。您将在此处看到这种声音的频谱图:
spectrogram of concatenated sound which is perceived with several 'soft' clicks
2) 当我生成声音时,有时除了这些更柔和的咔嗒声之外,还会有更明显的咔嗒声。这在频谱图中清晰可见。 --> 在这里我不确定问题可能是什么以及如何避免它。
spectrogram of concatenated sound with additional distinct click
我如何生成声音的代码如下:
clear all;
close all;
%% define stimulus parameters
soundDuration = 1200; % duration of sound
sf = 44100; % sampling rate
ampl = 0.05; % 0.05; % ampl
segmentDuration = 25; % duration of one standard segment in ms
nSegments = soundDuration/segmentDuration; % number of segments of which the sound should consist of
t = 0:1/sf:(0.025-1/sf); % time vector for segment
%% generate sound consisting of n sweep-segments
complexSound = [];
for iSeg = 1:nSegments
f1 = 1000:10:3000;
f1 = randsample(f1,1); % start freq in Hz for current sweep segment
f2 = 1500:10:4500;
f2 = randsample(f2,1); % end freq in Hz for current sweep segment
if iSeg == 1
sweep = ampl * chirp(t,f1,segmentDuration/1000,f2,'logarithmic'); % generate sweep-segment withou considering the phase
else
sweep = ampl * chirp(t+1/sf,f1,segmentDuration/1000,f2,'logarithmic',ph); % the current sweep starts with a t+1/sf later and with the phase angle with which the previous sweep ended
end
ph = -90+360*(f2*t(end)+1/sf); % calculate the phase at the time point at which the current sweep ends and from that calculate the starting phase for the next sweep
sweep = sweep';
complexSound = [complexSound; sweep]; % concatenate sweep segments to form the complex sound
end
stim = complexSound;
sound(stim,sf);
感谢您对解决这些问题的任何帮助。
【问题讨论】:
-
我发现了问题 2),它只是有时会发生。 chirp 函数的对数版本仅在 f1 和 f2 不同时有效。因此,可以通过代码轻松地限制这一点。