-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_Intan_RHD2000_file.m
608 lines (517 loc) · 21.1 KB
/
read_Intan_RHD2000_file.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
function read_Intan_RHD2000_file
% read_Intan_RHD2000_file
%
% Version 1.3, 10 December 2013
%
% Reads Intan Technologies RHD2000 data file generated by evaluation board
% GUI. Data are parsed and placed into variables that appear in the base
% MATLAB workspace. Therefore, it is recommended to execute a 'clear'
% command before running this program to clear all other variables from the
% base workspace.
%
% Example:
% >> clear
% >> read_Intan_RHD200_file
% >> whos
% >> amplifier_channels(1)
% >> plot(t_amplifier, amplifier_data(1,:))
[file, path, filterindex] = ...
uigetfile('*.rhd', 'Select an RHD2000 Data File', 'MultiSelect', 'off');
% Read most recent file automatically.
%path = 'C:\Users\Reid\Documents\RHD2132\testing\';
%d = dir([path '*.rhd']);
%file = d(end).name;
tic;
filename = [path,file];
fid = fopen(filename, 'r');
s = dir(filename);
filesize = s.bytes;
% Check 'magic number' at beginning of file to make sure this is an Intan
% Technologies RHD2000 data file.
magic_number = fread(fid, 1, 'uint32');
if magic_number ~= hex2dec('c6912702')
error('Unrecognized file type.');
end
% Read version number.
data_file_main_version_number = fread(fid, 1, 'int16');
data_file_secondary_version_number = fread(fid, 1, 'int16');
fprintf(1, '\n');
fprintf(1, 'Reading Intan Technologies RHD2000 Data File, Version %d.%d\n', ...
data_file_main_version_number, data_file_secondary_version_number);
fprintf(1, '\n');
% Read information of sampling rate and amplifier frequency settings.
sample_rate = fread(fid, 1, 'single');
dsp_enabled = fread(fid, 1, 'int16');
actual_dsp_cutoff_frequency = fread(fid, 1, 'single');
actual_lower_bandwidth = fread(fid, 1, 'single');
actual_upper_bandwidth = fread(fid, 1, 'single');
desired_dsp_cutoff_frequency = fread(fid, 1, 'single');
desired_lower_bandwidth = fread(fid, 1, 'single');
desired_upper_bandwidth = fread(fid, 1, 'single');
% This tells us if a software 50/60 Hz notch filter was enabled during
% the data acquisition.
notch_filter_mode = fread(fid, 1, 'int16');
notch_filter_frequency = 0;
if (notch_filter_mode == 1)
notch_filter_frequency = 50;
elseif (notch_filter_mode == 2)
notch_filter_frequency = 60;
end
desired_impedance_test_frequency = fread(fid, 1, 'single');
actual_impedance_test_frequency = fread(fid, 1, 'single');
% Place notes in data strucure
notes = struct( ...
'note1', fread_QString(fid), ...
'note2', fread_QString(fid), ...
'note3', fread_QString(fid) );
% If data file is from GUI v1.1 or later, see if temperature sensor data
% was saved.
num_temp_sensor_channels = 0;
if ((data_file_main_version_number == 1 && data_file_secondary_version_number >= 1) ...
|| (data_file_main_version_number > 1))
num_temp_sensor_channels = fread(fid, 1, 'int16');
end
% If data file is from GUI v1.3 or later, load eval board mode.
eval_board_mode = 0;
if ((data_file_main_version_number == 1 && data_file_secondary_version_number >= 3) ...
|| (data_file_main_version_number > 1))
eval_board_mode = fread(fid, 1, 'int16');
end
% Place frequency-related information in data structure.
frequency_parameters = struct( ...
'amplifier_sample_rate', sample_rate, ...
'aux_input_sample_rate', sample_rate / 4, ...
'supply_voltage_sample_rate', sample_rate / 60, ...
'board_adc_sample_rate', sample_rate, ...
'board_dig_in_sample_rate', sample_rate, ...
'desired_dsp_cutoff_frequency', desired_dsp_cutoff_frequency, ...
'actual_dsp_cutoff_frequency', actual_dsp_cutoff_frequency, ...
'dsp_enabled', dsp_enabled, ...
'desired_lower_bandwidth', desired_lower_bandwidth, ...
'actual_lower_bandwidth', actual_lower_bandwidth, ...
'desired_upper_bandwidth', desired_upper_bandwidth, ...
'actual_upper_bandwidth', actual_upper_bandwidth, ...
'notch_filter_frequency', notch_filter_frequency, ...
'desired_impedance_test_frequency', desired_impedance_test_frequency, ...
'actual_impedance_test_frequency', actual_impedance_test_frequency );
% Define data structure for spike trigger settings.
spike_trigger_struct = struct( ...
'voltage_trigger_mode', {}, ...
'voltage_threshold', {}, ...
'digital_trigger_channel', {}, ...
'digital_edge_polarity', {} );
new_trigger_channel = struct(spike_trigger_struct);
spike_triggers = struct(spike_trigger_struct);
% Define data structure for data channels.
channel_struct = struct( ...
'native_channel_name', {}, ...
'custom_channel_name', {}, ...
'native_order', {}, ...
'custom_order', {}, ...
'board_stream', {}, ...
'chip_channel', {}, ...
'port_name', {}, ...
'port_prefix', {}, ...
'port_number', {}, ...
'electrode_impedance_magnitude', {}, ...
'electrode_impedance_phase', {} );
new_channel = struct(channel_struct);
% Create structure arrays for each type of data channel.
amplifier_channels = struct(channel_struct);
aux_input_channels = struct(channel_struct);
supply_voltage_channels = struct(channel_struct);
board_adc_channels = struct(channel_struct);
board_dig_in_channels = struct(channel_struct);
board_dig_out_channels = struct(channel_struct);
amplifier_index = 1;
aux_input_index = 1;
supply_voltage_index = 1;
board_adc_index = 1;
board_dig_in_index = 1;
board_dig_out_index = 1;
% Read signal summary from data file header.
number_of_signal_groups = fread(fid, 1, 'int16');
for signal_group = 1:number_of_signal_groups
signal_group_name = fread_QString(fid);
signal_group_prefix = fread_QString(fid);
signal_group_enabled = fread(fid, 1, 'int16');
signal_group_num_channels = fread(fid, 1, 'int16');
signal_group_num_amp_channels = fread(fid, 1, 'int16');
if (signal_group_num_channels > 0 && signal_group_enabled > 0)
new_channel(1).port_name = signal_group_name;
new_channel(1).port_prefix = signal_group_prefix;
new_channel(1).port_number = signal_group;
for signal_channel = 1:signal_group_num_channels
new_channel(1).native_channel_name = fread_QString(fid);
new_channel(1).custom_channel_name = fread_QString(fid);
new_channel(1).native_order = fread(fid, 1, 'int16');
new_channel(1).custom_order = fread(fid, 1, 'int16');
signal_type = fread(fid, 1, 'int16');
channel_enabled = fread(fid, 1, 'int16');
new_channel(1).chip_channel = fread(fid, 1, 'int16');
new_channel(1).board_stream = fread(fid, 1, 'int16');
new_trigger_channel(1).voltage_trigger_mode = fread(fid, 1, 'int16');
new_trigger_channel(1).voltage_threshold = fread(fid, 1, 'int16');
new_trigger_channel(1).digital_trigger_channel = fread(fid, 1, 'int16');
new_trigger_channel(1).digital_edge_polarity = fread(fid, 1, 'int16');
new_channel(1).electrode_impedance_magnitude = fread(fid, 1, 'single');
new_channel(1).electrode_impedance_phase = fread(fid, 1, 'single');
if (channel_enabled)
switch (signal_type)
case 0
amplifier_channels(amplifier_index) = new_channel;
spike_triggers(amplifier_index) = new_trigger_channel;
amplifier_index = amplifier_index + 1;
case 1
aux_input_channels(aux_input_index) = new_channel;
aux_input_index = aux_input_index + 1;
case 2
supply_voltage_channels(supply_voltage_index) = new_channel;
supply_voltage_index = supply_voltage_index + 1;
case 3
board_adc_channels(board_adc_index) = new_channel;
board_adc_index = board_adc_index + 1;
case 4
board_dig_in_channels(board_dig_in_index) = new_channel;
board_dig_in_index = board_dig_in_index + 1;
case 5
board_dig_out_channels(board_dig_out_index) = new_channel;
board_dig_out_index = board_dig_out_index + 1;
otherwise
error('Unknown channel type');
end
end
end
end
end
% Summarize contents of data file.
num_amplifier_channels = amplifier_index - 1;
num_aux_input_channels = aux_input_index - 1;
num_supply_voltage_channels = supply_voltage_index - 1;
num_board_adc_channels = board_adc_index - 1;
num_board_dig_in_channels = board_dig_in_index - 1;
num_board_dig_out_channels = board_dig_out_index - 1;
fprintf(1, 'Found %d amplifier channel%s.\n', ...
num_amplifier_channels, plural(num_amplifier_channels));
fprintf(1, 'Found %d auxiliary input channel%s.\n', ...
num_aux_input_channels, plural(num_aux_input_channels));
fprintf(1, 'Found %d supply voltage channel%s.\n', ...
num_supply_voltage_channels, plural(num_supply_voltage_channels));
fprintf(1, 'Found %d board ADC channel%s.\n', ...
num_board_adc_channels, plural(num_board_adc_channels));
fprintf(1, 'Found %d board digital input channel%s.\n', ...
num_board_dig_in_channels, plural(num_board_dig_in_channels));
fprintf(1, 'Found %d board digital output channel%s.\n', ...
num_board_dig_out_channels, plural(num_board_dig_out_channels));
fprintf(1, 'Found %d temperature sensors channel%s.\n', ...
num_temp_sensor_channels, plural(num_temp_sensor_channels));
fprintf(1, '\n');
% Determine how many samples the data file contains.
% Each data block contains 60 amplifier samples.
bytes_per_block = 60 * 4; % timestamp data
bytes_per_block = bytes_per_block + 60 * 2 * num_amplifier_channels;
% Auxiliary inputs are sampled 4x slower than amplifiers
bytes_per_block = bytes_per_block + 15 * 2 * num_aux_input_channels;
% Supply voltage is sampled 60x slower than amplifiers
bytes_per_block = bytes_per_block + 1 * 2 * num_supply_voltage_channels;
% Board analog inputs are sampled at same rate as amplifiers
bytes_per_block = bytes_per_block + 60 * 2 * num_board_adc_channels;
% Board digital inputs are sampled at same rate as amplifiers
if (num_board_dig_in_channels > 0)
bytes_per_block = bytes_per_block + 60 * 2;
end
% Board digital outputs are sampled at same rate as amplifiers
if (num_board_dig_out_channels > 0)
bytes_per_block = bytes_per_block + 60 * 2;
end
% Temp sensor is sampled 60x slower than amplifiers
if (num_temp_sensor_channels > 0)
bytes_per_block = bytes_per_block + 1 * 2 * num_temp_sensor_channels;
end
% How many data blocks remain in this file?
data_present = 0;
bytes_remaining = filesize - ftell(fid);
if (bytes_remaining > 0)
data_present = 1;
end
num_data_blocks = bytes_remaining / bytes_per_block;
num_amplifier_samples = 60 * num_data_blocks;
num_aux_input_samples = 15 * num_data_blocks;
num_supply_voltage_samples = 1 * num_data_blocks;
num_board_adc_samples = 60 * num_data_blocks;
num_board_dig_in_samples = 60 * num_data_blocks;
num_board_dig_out_samples = 60 * num_data_blocks;
record_time = num_amplifier_samples / sample_rate;
if (data_present)
fprintf(1, 'File contains %0.3f seconds of data. Amplifiers were sampled at %0.2f kS/s.\n', ...
record_time, sample_rate / 1000);
fprintf(1, '\n');
else
fprintf(1, 'Header file contains no data. Amplifiers were sampled at %0.2f kS/s.\n', ...
sample_rate / 1000);
fprintf(1, '\n');
end
if (data_present)
% Pre-allocate memory for data.
fprintf(1, 'Allocating memory for data...\n');
t_amplifier = zeros(1, num_amplifier_samples);
amplifier_data = zeros(num_amplifier_channels, num_amplifier_samples);
aux_input_data = zeros(num_aux_input_channels, num_aux_input_samples);
supply_voltage_data = zeros(num_supply_voltage_channels, num_supply_voltage_samples);
temp_sensor_data = zeros(num_temp_sensor_channels, num_supply_voltage_samples);
board_adc_data = zeros(num_board_adc_channels, num_board_adc_samples);
board_dig_in_data = zeros(num_board_dig_in_channels, num_board_dig_in_samples);
board_dig_in_raw = zeros(1, num_board_dig_in_samples);
board_dig_out_data = zeros(num_board_dig_out_channels, num_board_dig_out_samples);
board_dig_out_raw = zeros(1, num_board_dig_out_samples);
% Read sampled data from file.
fprintf(1, 'Reading data from file...\n');
amplifier_index = 1;
aux_input_index = 1;
supply_voltage_index = 1;
board_adc_index = 1;
board_dig_in_index = 1;
board_dig_out_index = 1;
print_increment = 10;
percent_done = print_increment;
for i=1:num_data_blocks
% In version 1.2, we moved from saving timestamps as unsigned
% integeters to signed integers to accomidate negative (adjusted)
% timestamps for pretrigger data.
if ((data_file_main_version_number == 1 && data_file_secondary_version_number >= 2) ...
|| (data_file_main_version_number > 1))
t_amplifier(amplifier_index:(amplifier_index+59)) = fread(fid, 60, 'int32');
else
t_amplifier(amplifier_index:(amplifier_index+59)) = fread(fid, 60, 'uint32');
end
if (num_amplifier_channels > 0)
amplifier_data(:, amplifier_index:(amplifier_index+59)) = fread(fid, [60, num_amplifier_channels], 'uint16')';
end
if (num_aux_input_channels > 0)
aux_input_data(:, aux_input_index:(aux_input_index+14)) = fread(fid, [15, num_aux_input_channels], 'uint16')';
end
if (num_supply_voltage_channels > 0)
supply_voltage_data(:, supply_voltage_index) = fread(fid, [1, num_supply_voltage_channels], 'uint16')';
end
if (num_temp_sensor_channels > 0)
temp_sensor_data(:, supply_voltage_index) = fread(fid, [1, num_temp_sensor_channels], 'int16')';
end
if (num_board_adc_channels > 0)
board_adc_data(:, board_adc_index:(board_adc_index+59)) = fread(fid, [60, num_board_adc_channels], 'uint16')';
end
if (num_board_dig_in_channels > 0)
board_dig_in_raw(board_dig_in_index:(board_dig_in_index+59)) = fread(fid, 60, 'uint16');
end
if (num_board_dig_out_channels > 0)
board_dig_out_raw(board_dig_out_index:(board_dig_out_index+59)) = fread(fid, 60, 'uint16');
end
amplifier_index = amplifier_index + 60;
aux_input_index = aux_input_index + 15;
supply_voltage_index = supply_voltage_index + 1;
board_adc_index = board_adc_index + 60;
board_dig_in_index = board_dig_in_index + 60;
board_dig_out_index = board_dig_out_index + 60;
fraction_done = 100 * (i / num_data_blocks);
if (fraction_done >= percent_done)
fprintf(1, '%d%% done...\n', percent_done);
percent_done = percent_done + print_increment;
end
end
% Make sure we have read exactly the right amount of data.
bytes_remaining = filesize - ftell(fid);
if (bytes_remaining ~= 0)
%error('Error: End of file not reached.');
end
end
% Close data file.
fclose(fid);
if (data_present)
fprintf(1, 'Parsing data...\n');
% Extract digital input channels to separate variables.
for i=1:num_board_dig_in_channels
mask = 2^(board_dig_in_channels(i).native_order) * ones(size(board_dig_in_raw));
board_dig_in_data(i, :) = (bitand(board_dig_in_raw, mask) > 0);
end
for i=1:num_board_dig_out_channels
mask = 2^(board_dig_out_channels(i).native_order) * ones(size(board_dig_out_raw));
board_dig_out_data(i, :) = (bitand(board_dig_out_raw, mask) > 0);
end
% Scale voltage levels appropriately.
amplifier_data = 0.195 * (amplifier_data - 32768); % units = microvolts
aux_input_data = 37.4e-6 * aux_input_data; % units = volts
supply_voltage_data = 74.8e-6 * supply_voltage_data; % units = volts
if (eval_board_mode == 1)
board_adc_data = 152.59e-6 * (board_adc_data - 32768); % units = volts
else
board_adc_data = 50.354e-6 * board_adc_data; % units = volts
end
temp_sensor_data = temp_sensor_data / 100; % units = deg C
% Check for gaps in timestamps.
num_gaps = sum(diff(t_amplifier) ~= 1);
if (num_gaps == 0)
fprintf(1, 'No missing timestamps in data.\n');
else
fprintf(1, 'Warning: %d gaps in timestamp data found. Time scale will not be uniform!\n', ...
num_gaps);
end
% Scale time steps (units = seconds).
t_amplifier = t_amplifier / sample_rate;
t_aux_input = t_amplifier(1:4:end);
t_supply_voltage = t_amplifier(1:60:end);
t_board_adc = t_amplifier;
t_dig = t_amplifier;
t_temp_sensor = t_supply_voltage;
% If the software notch filter was selected during the recording, apply the
% same notch filter to amplifier data here.
if (notch_filter_frequency > 0)
fprintf(1, 'Applying notch filter...\n');
print_increment = 10;
percent_done = print_increment;
for i=1:num_amplifier_channels
amplifier_data(i,:) = ...
notch_filter(amplifier_data(i,:), sample_rate, notch_filter_frequency, 10);
fraction_done = 100 * (i / num_amplifier_channels);
if (fraction_done >= percent_done)
fprintf(1, '%d%% done...\n', percent_done);
percent_done = percent_done + print_increment;
end
end
end
end
% Move variables to base workspace.
move_to_base_workspace(notes);
move_to_base_workspace(frequency_parameters);
move_to_base_workspace(file);
move_to_base_workspace(path);
if (num_amplifier_channels > 0)
move_to_base_workspace(amplifier_channels);
if (data_present)
move_to_base_workspace(amplifier_data);
move_to_base_workspace(t_amplifier);
end
move_to_base_workspace(spike_triggers);
end
if (num_aux_input_channels > 0)
move_to_base_workspace(aux_input_channels);
if (data_present)
move_to_base_workspace(aux_input_data);
move_to_base_workspace(t_aux_input);
end
end
if (num_supply_voltage_channels > 0)
move_to_base_workspace(supply_voltage_channels);
if (data_present)
move_to_base_workspace(supply_voltage_data);
move_to_base_workspace(t_supply_voltage);
end
end
if (num_board_adc_channels > 0)
move_to_base_workspace(board_adc_channels);
if (data_present)
move_to_base_workspace(board_adc_data);
move_to_base_workspace(t_board_adc);
end
end
if (num_board_dig_in_channels > 0)
move_to_base_workspace(board_dig_in_channels);
if (data_present)
move_to_base_workspace(board_dig_in_data);
move_to_base_workspace(t_dig);
end
end
if (num_board_dig_out_channels > 0)
move_to_base_workspace(board_dig_out_channels);
if (data_present)
move_to_base_workspace(board_dig_out_data);
move_to_base_workspace(t_dig);
end
end
if (num_temp_sensor_channels > 0)
if (data_present)
move_to_base_workspace(temp_sensor_data);
move_to_base_workspace(t_temp_sensor);
end
end
fprintf(1, 'Done! Elapsed time: %0.1f seconds\n', toc);
if (data_present)
fprintf(1, 'Extracted data are now available in the MATLAB workspace.\n');
else
fprintf(1, 'Extracted waveform information is now available in the MATLAB workspace.\n');
end
fprintf(1, 'Type ''whos'' to see variables.\n');
fprintf(1, '\n');
return
function a = fread_QString(fid)
% a = read_QString(fid)
%
% Read Qt style QString. The first 32-bit unsigned number indicates
% the length of the string (in bytes). If this number equals 0xFFFFFFFF,
% the string is null.
a = '';
length = fread(fid, 1, 'uint32');
if length == hex2num('ffffffff')
return;
end
% convert length from bytes to 16-bit Unicode words
length = length / 2;
for i=1:length
a(i) = fread(fid, 1, 'uint16');
end
return
function s = plural(n)
% s = plural(n)
%
% Utility function to optionally plurailze words based on the value
% of n.
if (n == 1)
s = '';
else
s = 's';
end
return
function out = notch_filter(in, fSample, fNotch, Bandwidth)
% out = notch_filter(in, fSample, fNotch, Bandwidth)
%
% Implements a notch filter (e.g., for 50 or 60 Hz) on vector 'in'.
% fSample = sample rate of data (in Hz or Samples/sec)
% fNotch = filter notch frequency (in Hz)
% Bandwidth = notch 3-dB bandwidth (in Hz). A bandwidth of 10 Hz is
% recommended for 50 or 60 Hz notch filters; narrower bandwidths lead to
% poor time-domain properties with an extended ringing response to
% transient disturbances.
%
% Example: If neural data was sampled at 30 kSamples/sec
% and you wish to implement a 60 Hz notch filter:
%
% out = notch_filter(in, 30000, 60, 10);
tstep = 1/fSample;
Fc = fNotch*tstep;
L = length(in);
% Calculate IIR filter parameters
d = exp(-2*pi*(Bandwidth/2)*tstep);
b = (1 + d*d)*cos(2*pi*Fc);
a0 = 1;
a1 = -b;
a2 = d*d;
a = (1 + d*d)/2;
b0 = 1;
b1 = -2*cos(2*pi*Fc);
b2 = 1;
out = zeros(size(in));
out(1) = in(1);
out(2) = in(2);
% (If filtering a continuous data stream, change out(1) and out(2) to the
% previous final two values of out.)
% Run filter
for i=3:L
out(i) = (a*b2*in(i-2) + a*b1*in(i-1) + a*b0*in(i) - a2*out(i-2) - a1*out(i-1))/a0;
end
return
function move_to_base_workspace(variable)
% move_to_base_workspace(variable)
%
% Move variable from function workspace to base MATLAB workspace so
% user will have access to it after the program ends.
variable_name = inputname(1);
assignin('base', variable_name, variable);
return;