- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想通过 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);
对于解决这些问题的任何帮助,我都很感激。
最佳答案
所以,基本上你想要的是调频。嗯,不是真的,但我们基本上可以滥用 matlab 为它提供的功能。诀窍是这样的:
我尝试调整您的代码并使其尽可能相似。但是,现在所有持续时间都以秒为单位。
请注意,我假设各个段之间的边缘没问题。因此,如果您有一段以 1500Hz 结束,而下一段以 2000Hz 开始,则这两者之间没有平滑的进展。也许 fmmod 函数可以稍微平滑一点,但我没有检查。
但是,这里是代码:
%% clear
clear all;
close all;
%% define stimulus parameters
soundDuration = 1.2; % duration of sound in seconds
sf = 44100; % sampling rate
ampl = 0.05; % 0.05; % ampl
segmentDuration = 0.025; % duration of one standard segment in s
nSegments = round(soundDuration/segmentDuration); % number of segments of which the sound should consist of
samples_per_segment = floor(sf * segmentDuration);
%% generate sound consisting of n sweep-segments
modulator = zeros(1, nSegments * samples_per_segment);
first_idx = 1;
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
modulator(first_idx:first_idx + samples_per_segment-1) = logspace(log10(f1), log10(f2), samples_per_segment); % we add the logarithmic progression from f1 to f2 here
first_idx = first_idx + samples_per_segment;
end
%% create final sound
stim = fmmod(modulator, 1, sf, 1); % here we abuse the frequency modulation function of matlab.
% we basically tell it to create a 1Hz
% sinewave and modulate it by the vector
% we created in the previous step. the
% last argument tells it basically that
% if i give it a 1, it should increase
% the frequency by 1Hz, if i give it a
% 100, it should increase the freq by
% 100Hz and so on...
stim = ampl .* stim; % multiply by the amplitude
%% plot...
spectrogram(stim,1000,[],[],sf,'yaxis'); % this provides a nice tf plot....
%% play
sound(stim,sf);
关于matlab - 如何通过 MATLAB 生成由不同频率滑音段组成的声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39644097/
我是一名优秀的程序员,十分优秀!