生成特定持续时间内的频率的斜坡音频信号

时间:2017-04-07 02:47:51

标签: matlab audio

我希望产生10hz到1000hz的频率,步长为10hz,假设在5s内(所有频率在时间范围内均匀分布)。如何通过下面的单个频率发生器功能实现这一目标?

function [ ] = producefeq( frequency, duration, amplitude, freqsampling )

if ~exist('freqsampling', 'var'), freqsampling = 44100; end
if ~exist('amplitude', 'var'), amplitude = 1; end
if nargin <2, error('Not enough input arguments'); end

% the frequency argument will be like this for the case above 10:10:1000

t = 0:(1/freqsampling):duration;
y = amplitude*sin(2*pi*frequency*t);
sound(y, freqsampling);

end

提前致谢!

1 个答案:

答案 0 :(得分:0)

您可以多次致电producefeq并使用pause在多次执行之间等待。

totalDuration = 500;
frequencies = 10:10:1000;
duration = totalDuration/length(frequencies);

for i = 1:length(frequencies)
    producefeq( frequencies(i), duration)
    pause(duration)
end