Can't get user INPUT function to work!!!
4 views (last 30 days)
Show older comments
I've written a quick function for a class I'm taking that removes frequencies below a specified value from an input .wav file. The function works great, but I wanted to add the ability for the user to listen to the new .wav file at the end of the function. To do this, I was trying to use the "input" function to prompt the user. My script is as follows:
function low_pass_filter(wavfile,limit,filename)
if nargin==2
filename=('low_pass_output.wav');
end
if isstr(wavfile) && isstr(filename)
[input,FS,NBITS]=wavread(wavfile);
else
error('Inputs wavfile and name must be strings')
end
%Perfom fast fourier tranform
ft=fft(input);
L=length(ft);
% Split transform in half
ft_cut=ft(1:L/2+1);
ft_new=zeros(L,1);
%Find and remove frequencies less than limit
freq_vec = [1/7:1/7:22050];
ind_lf = find(freq_vec < limit);
ft_cut(ind_lf(2:end))=0;
% Reconstruct fourier transform
ft_new(1:L/2+1)=ft_cut;
x = [length(ft_cut) : -1 : 2]';
ft_new((L/2)+1:L)=conj(ft_cut(x));
% Inverse fourier transform
wavfile_new=ifft(ft_new);
% Write new .wav file
wavwrite(wavfile_new,FS,NBITS,filename)
prompt='Would you like to play the edited .wav file?'
reply = input(prompt,'s')
if reply=='Y'
sound(wavfile_new,FS)
end
The part at the end was my attempt to play the file. Just tacking on sound(wavefile_new,FS) at the end of the function will play the file, but using the "input" function as above returns this error:
??? Index exceeds matrix dimensions.
Error in ==> risk_low_pass_filter at 60
reply = input(prompt,'s')
0 Comments
Accepted Answer
Sean de Wolski
on 6 Dec 2011
You overwrite the function input with the variable input as the output from your call to wavread on line 6. Thus it sees input as a variable and it's trying to index it with prompt and 's'.
0 Comments
More Answers (1)
See Also
Categories
Find more on Audio I/O and Waveform Generation 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!