-
Notifications
You must be signed in to change notification settings - Fork 4
/
freq2delta.m
41 lines (32 loc) · 1.81 KB
/
freq2delta.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function delta = freq2delta(frequency, waveformSize, maxBufferSize, dacFrequency)
% FREQ2DELTA Convert frequency to delta value for PicoScope Arbitrary Waveform Generators.
% freq2delta(F, W, B, D) converts a frequency value F in hertz into a
% uint32 delta phase value using the waveform size W, maximum buffer size
% of the PicoScope device B and DAC Frequency of the Arbitrary Waveform
% Generator, D.
%
% F can be any numeric value such as DOUBLE and can be a scalar value or
% vector of 2 elements corresponding to a start and stop frequency.
% W should ideally be a signed 16-bit or 32-bit integer, while B and D
% will be defined by the properties of the PicoScope device being used
% when using the Instrument Driver, otherwise they should be signed
% 32-bit integers.
%
% The delta phase value is returned as an unsigned 32-bit integer.
%
% Copyright: © 2013 - 2015 Pico Technology Ltd. All rights reserved.
% Validate Input parameters
validateattributes(frequency, {'numeric'}, {'vector', 'real', 'finite', 'nonnegative'});
validateattributes(waveformSize, {'numeric'}, {'scalar', 'integer', 'positive'});
validateattributes(maxBufferSize, {'numeric'}, {'scalar', 'integer', 'positive'});
validateattributes(dacFrequency, {'numeric'}, {'scalar', 'real', 'finite', 'positive'});
% Use only the first two values for frequency if it contains more than
% 2 elements
if(length(frequency) > 2)
frequency = frequency([1 2]);
warning('Freq2Delta:TooManyElements', 'First two elements of frequency vector will be used.');
end
% Calculate the delta phase value
delta = uint32(((frequency * waveformSize) / maxBufferSize) * ...
PicoConstants.AWG_PHASE_ACCUMULATOR * (1/dacFrequency));
end