MATLAB: Convert .csv to .wav audio

csvMATLABwav

I am fairly new to matlab
I wanted to convert a comma separated value (.csv) file to a Wave (.wav) audio file while also plotting it.
I saw this previously answered Here on matlab answers but I had a few questions and some errors, for the sake of simplicity I have attached the code and the csv file here
error shown is
Undefined function or variable 'y'.
Error in Untitled (line 17)
audiowrite('audio_output.wav',y,Fs)
and I did not understand why in the code the variable 'y' and 'Fs' are there in code
clc;
clear all;
close all;
data=csvread("output.csv");
time=data(: ,1);
output=data(: ,2);
plot(time,output);
save('aec.mat','time','output');
load aec.mat
filename='audio_output.wav';
Fs=6000;
audiowrite('audio_output.wav',y,Fs)
clear y Fs
[y,Fs]=audioread(filename);
sound(y,Fs);

Best Answer

Debagnik - the y variable represents the audio samples. In your case, that would be output. Just change your code to the following
time = data(: ,1);
y = data(: ,2);
plot(time, y);
I see that you have set the sampling rate, Fs, to be 6000...just like in the link that you have provided. If your time data is in seconds, then it looks like you have 2.5 seconds (time(end) - time(1)) worth of data. Since there are 108569 (length(output)) samples, then this would mean your Fs could be
Fs = length(output) / (time(end) - time(1)); % 43427.6
Is this correct? Or is your sampling freqency really 6000?