help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Frequency sweep range issue


From: Børge Strand-Bergesen
Subject: Frequency sweep range issue
Date: Sun, 3 Jul 2016 18:13:59 +0200

Hi guys,

I'm writing a diy chirp function to generate an audio test signal. My code is virtually identical to several examples I find on line. I test the generated audio signal frequency on a digital oscilloscope using a USB DAC for playback. (The DAC is the actual device under test, but it does not mess up frequencies.)

The weird thing is: When I specify a start and stop frequency, the resulting chirp starts at the right place but then goes in frequency by twice the gab between start and stop.

The code below will illustrate the problem. Exporting a .wav or using soundsc doesn't change anything, the output frequency span is doubled.

When I plot the frequency variable, everything looks fine. As is the case when I use the same kind of code to generate a static frequency. And chirp() seems to generate correct output.

This is driving me nuts, is there something which I (and a lot of other guys online) have missed?

System is Win10/64 with a fresh install of Octave 4.0.3.

Thanks for your input,

Borge

f_start = 20; % Frequency in Hz
f_end = 200;
fs = 44100; % sample rate in Hz
res = 24; % bits
dur = 10; % duration in seconds

clear f t;
for n = 0:fs*dur
  f(n+1) = f_start + (f_end - f_start) * n / (fs * dur);
end;
t=0:1/fs:dur;
x = 0.5*sin(2*pi*f.*t);

% Straight line from 20 to 200
plot (f);

% Sweeps from 20 to 380Hz
wavwrite ([x' x'], fs, res, "c:/music/Test_wav/sweep_20_200_24_6dB.wav");

% Sweeps from 20 to 380Hz
soundsc (x, fs);

% Spot-on 200Hz playback
y = 0.5 * sin(2*pi*200.*t);
soundsc (y, fs);

% Trying the same thing with chirp()
y = 0.5 * chirp([0:1/fs:10], 20, 10, 200, "linear");

% Comparing, x looks like a bit more than twice the frequency of y
hold off
plot (x(440000: 441001), 'r');
hold on
plot (y(440000: 441001), 'b');


reply via email to

[Prev in Thread] Current Thread [Next in Thread]