Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated DSBF and added more convience to clean up the models. #89

Merged
merged 4 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions autogen/AudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
properties
audio
sampleRateHz
dataType
end

properties(SetAccess = private)
Expand All @@ -28,13 +29,18 @@
end

methods
function obj = AudioSource(audio, sampleRateHz)
function obj = AudioSource(audio, sampleRateHz, dataType)
%AudioSource Initializes AudioSource with m x n audio input and
% sample rate in hz, where m is the the number of samples and n is
% the number of channels.

obj.sampleRateHz = sampleRateHz;
obj.audio = audio;
if exist('dataType','var')
obj.dataType = dataType;
else
obj.dataType = fixdt(1,24,23);
end
tvannoy marked this conversation as resolved.
Show resolved Hide resolved
end

function obj = set.audio(obj, audio)
Expand Down Expand Up @@ -71,12 +77,13 @@
% requires the input to be time series. Call this method
% to use an AudioSource in Simulink simulations.
time = [0:(obj.nSamples - 1)] / obj.sampleRateHz;
ts = timeseries(obj.audio, time);
fix_audio = fi(obj.audio, obj.dataType);
ts = timeseries(fix_audio, time);
end
end

methods(Static)
function audioSource = fromFile(filepath, sampleRate, nSamples)
function audioSource = fromFile(filepath, sampleRate, nSamples, dataType)
info = audioinfo(filepath);
fileFs = info.SampleRate;

Expand All @@ -91,7 +98,7 @@
end
yResampled = resample(y,sampleRate, fileFs);

audioSource = AudioSource(yResampled, sampleRate);
audioSource = AudioSource(yResampled, sampleRate, dataType);
end
end

Expand Down
16 changes: 15 additions & 1 deletion autogen/configureModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
mp.signed = config.system.audioIn.signed;
mp.W_bits = config.system.audioIn.wordLength; % Word length
mp.F_bits = config.system.audioIn.fractionLength; % Number of fractional bits in word
mp.audio_dt = fixdt(mp.signed, mp.W_bits, mp.F_bits);
mp.nChannels = config.system.audioIn.numberOfChannels;
mp.nOutChannels = config.system.audioOut.numberOfChannels;

Expand Down Expand Up @@ -76,6 +77,18 @@
mp.Ts_sim = 1/(mp.Fs * mp.nChannels); % System clock period
mp.rate_change = mp.Fs_system/mp.Fs; % how much faster the system clock is to the sample clock

regSize = size(mp.register);
nRegs = regSize(1);
tempRegs = containers.Map();
for idx=1:nRegs
tempRegs(mp.register{idx}.name) = mp.register{idx};
end


mp.getReg = tempRegs;
tvannoy marked this conversation as resolved.
Show resolved Hide resolved
clear tempRegs;
clear nRegs;
clear regSize;

%% Helper functions
function regs = parseregisters(config)
Expand All @@ -100,14 +113,15 @@
reg = device.registers{idx};
end
tempReg.name = reg.name;
tempReg.value = reg.defaultValue;

if reg.dataType.type == "boolean"
tempReg.dataType = fixdt('boolean');
else
tempReg.dataType = fixdt(reg.dataType.signed, ...
reg.dataType.wordLength, reg.dataType.fractionLength);
end

tempReg.value = fi(reg.defaultValue, tempReg.dataType);
tempReg.timeseries = timeseries(tempReg.value, 0);

regs{idx} = tempReg;
Expand Down
2 changes: 1 addition & 1 deletion autogen/initCallback.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

configureModel;

testSignal = AudioSource.fromFile(mp.testFile, mp.Fs, mp.nSamples);
testSignal = AudioSource.fromFile(mp.testFile, mp.Fs, mp.nSamples, mp.audio_dt);
stopTime = testSignal.duration;

nSamples = testSignal.nSamples;
Expand Down
Binary file modified models/delay_and_sum_beamformer/DSBF.slx
Binary file not shown.
130 changes: 0 additions & 130 deletions models/delay_and_sum_beamformer/DSBF_dataplane.json

This file was deleted.

2 changes: 1 addition & 1 deletion models/delay_and_sum_beamformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The basic idea behind [beamforming](https://en.wikipedia.org/wiki/Beamforming) i

## Usage
- `Azimuth`: The horizontal steering angle in degrees (audio coming from this direction is reinforced); this ranges between +/-90 degrees.
- `Elevation`: The vertical steering angle in degrees (audio coming from this direction is reincofreced); this ranges between +/-90 degrees.
- `Elevation`: The vertical steering angle in degrees (audio coming from this direction is reinforced); this ranges between +/-90 degrees.

## Implementation
The following block diagram shows a high-level view of the implementation.
Expand Down
8 changes: 4 additions & 4 deletions models/delay_and_sum_beamformer/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"systemClockFrequency": 98304000,
"processing": "sample",
"audioIn": {
"wordLength": 32,
"fractionLength": 28,
"wordLength": 24,
"fractionLength": 23,
"signed": true,
"numberOfChannels": 16
},
"audioOut": {
"wordLength": 32,
"fractionLength": 28,
"wordLength": 24,
"fractionLength": 23,
"signed": true,
"numberOfChannels": 2
}
Expand Down
23 changes: 6 additions & 17 deletions models/delay_and_sum_beamformer/modelparameters.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,31 @@

mp.testFile = [mp.test_signals_path filesep 'beamformer_test.wav'];

% TODO: use booleans instead of 0 and 1
mp.sim_prompts = 0;
mp.sim_verify = 0;
mp.sim_verify = 1;
mp.simDuration = .03;
mp.nSamples = config.system.sampleClockFrequency * mp.simDuration;

%% Exponential moving average setup

% % 10 ms window
% mp.windowSize = 10e-3 * mp.Fs;
%
% % define the exponential moving average weight to be roughly equivalent to
% % a simple moving average of length mp.windowSize
% % https://en.wikipedia.org/wiki/Moving_average#Relationship_between_SMA_and_EMA
% mp.exponentialMovingAverageWeight = fi(2/(mp.windowSize + 1), 0, 32, 31);

mp.speedOfSound = 343;

% TODO: it'd sure be nice to have access to mp.Fs right here, but we don't....
mp.samplingRate = 48e3;
mp.samplingRate = mp.Fs;
mp.arraySpacing = 25e-3;
mp.arraySize = [4,4];
arraySize = mp.arraySize;
arraySpacing = mp.arraySpacing;
samplingRate = mp.samplingRate;
speedOfSound = mp.speedOfSound;

% TODO: document this equation... this is across the entire array,
% but delays are relative to the array center, so delays are +/- maxDelay/2
% this is across the entire array, but delays are relative to the array
% center, so delays are +/- maxDelay/2
mp.maxDelay = sqrt(((mp.arraySize(1) - 1)*mp.arraySpacing).^2 + ((mp.arraySize(2) - 1)*mp.arraySpacing).^2)*mp.samplingRate/mp.speedOfSound;
% buffer size to accomodate max delay; buffer size is a power of 2

% buffer size to accomodate max delay; buffer size is a power of 2
mp.integerDelayAddrSize = ceil(log2(floor(mp.maxDelay))) + 2;
mp.integerDelayBufferSize = 2^mp.integerDelayAddrSize;
mp.upsampleFactor = 16;
upsampleFactor = mp.upsampleFactor;

% number of required bits is two more than that required to represent upsampleFactor
% because we need to be able to represent +/- upsample factor inclusive
mp.fractionalDelayAddrSize = ceil(log2(floor(mp.upsampleFactor))) + 2;
Expand Down
72 changes: 0 additions & 72 deletions models/delay_and_sum_beamformer/sm_callback_init.m

This file was deleted.

Loading