2017-04-07 129 views
0

我想要以10hz的频率产生10hz到1000hz的频率,比如在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 

在此先感谢!

回答

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