Can't get user INPUT function to work!!!
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sean de Wolski
2011년 12월 6일
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
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!