2017-04-07 70 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