Error with Audiowrite Struct contents reference from a non-struct array object.
Show older comments
For some reason when ever I run my code I collect data and am able to plot it but I get this error once I try saving the data using audio write:
*Struct contents reference from a non-struct array object.
Error in audiovideo.internal.FilePath/get.Absolute (line 119) pathstr = pathInfo.Name;
Error in audiowrite>validateFilename (line 305) if isempty(filepath.Absolute)
Error in audiowrite (line 105) [props.filename, fileExisted] = validateFilename( props.filename );
Error in tubetest (line 41) audiowrite(filename, data(:,2), Fs,'BitsPerSample',24)*
My code is
if true
filename=sprintf('extra sound data/tube_sounds1.wav')
%
NT=30000; % number of periods per frequency point used to set duration to 30 second sample
A=(.01) %amplitude in V
st = daq.createSession('ni'); %turns on the data aquisiontion hardware by Ni
Fs=88200; % Sample rate for output signal
st.Rate = Fs; % Sample rate for input signals
Ts=1/Fs; %time between samples, (100k)^-1 sec/sample
f=1000; %sets a reference frequency used only for time purposes
%
addAnalogOutputChannel(st,'cDAQ1Mod1',0,'Voltage'); % unused just quirk of hard ware
addAnalogOutputChannel(st,'cDAQ1Mod1',1,'Voltage'); % unused just quirk of hard ware
ch1 = addAnalogInputChannel(st,'cDAQ1Mod2',0,'Voltage'); % mic 1
ch2 = addAnalogInputChannel(st,'cDAQ1Mod2',1,'Voltage'); % mic 2
ch3 = addAnalogInputChannel(st,'cDAQ1Mod2',2,'Voltage'); % mic 3
ch4 = addAnalogInputChannel(st,'cDAQ1Mod2',3,'Voltage'); % mic 4
%
t=0:Ts:Ts*(fix(Fs/4)-1); % this is the time vector initial waiting time = 0.25 seconds bringing total to 30.25 seconds
outputSignalcos=t*0; unused just quirk of hard ware
outputSignalsin=t*0; unused just quirk of hard ware
for nf=1:length(f) %left over from old code we only have one f now and its 1000 Hz
tn=0:Ts:(NT/f(nf)-Ts); %time vector. NT/f(nf) is the amount of time that NF (30000) periods takes so 30 seconds
outputSignalcos = [outputSignalcos A*cos(2*pi*f(nf)*tn)]; % needed for collecting data quirk of hardware
outputSignalsin = [outputSignalsin A*sin(2*pi*f(nf)*tn)]; % needed for collecting data quirk of hardware
t=[t tn+t(end)];
en%d
%
%%-- Perform Frequency sweep --
disp(['performing frequency sweep...'])
queueOutputData(st,[outputSignalcos' outputSignalsin'])
data=st.startForeground; %starts collecting data
%
size(data) % returns 2668050 4 which is 30.25 seconds of 88.2 Khz sampled data
plot(data(:,2)) %plots the data from mic 2 we see good sound data that falls in between +-1
%
audiowrite(filename, data(:,2), Fs,'BitsPerSample',2
end
Answers (1)
Geoff Hayes
on 18 Apr 2017
0 votes
Massey - is extra sound data/ a valid path from within the current directory? Is / valid for your OS? Try giving the full path name and/or create a folder name without any spaces.
Categories
Find more on Discrete Fourier and Cosine Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!