필터 지우기
필터 지우기

how can i convert following script into c coding

조회 수: 3 (최근 30일)
Ahmed Hassan Sher
Ahmed Hassan Sher 2020년 6월 24일
댓글: Walter Roberson 2020년 6월 25일
[filename,pathname] = uigetfile('*.*','select audio');
[x,fs] = audioread(num2str(filename));
fsf = 44100;
fp = 8e3;
fst = 8.4e3;
ap = 1;
ast = 95;
df = designfilt('lowpassfir','passbandfrequency',fp,'stopbandfrequency',fst,'passbandripple',ap,'stopbandattenuation',ast,'samplerate',fsf);
fvtool(df);
xn=awgn(x,15,'measured');
y=filter(df,xn);
sound_input = y; %read the audio file into this array
sound_output = zeros(size(sound_input));
for i = 101:length(sound_input)
sum = 0;
for j = 1:100-1
a = sound_input(i-j);
c = b(j);
sum = sum + a.*(c);
end
sound_output(i) = sum;
end
figure
subplot(411);
plot(sound_input);
title('sound input');
subplot(412);
plot(sound_output);
title('sound output');
ORIGINAL = fft(sound_input,512);
Pyy1 = ORIGINAL .* conj(ORIGINAL) / 512;
FILTERED = fft(sound_output,512);
Pyy2 = FILTERED .* conj(FILTERED) / 512;
f = 1000*(0:256)/512;
figure
subplot(211)
plot(f,Pyy1(1:257))
title('Frequency content of original')
xlabel('frequency (Hz)')
subplot(212)
plot(f,Pyy2(1:257))
title('Frequency content of filtered')
xlabel('frequency (Hz)')
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 6월 25일
You cannot. uigetfile() returns a "number" only in the case that the user cancels, in which case it returns the empty double precision array; otherwise it returns a character vector. num2str() applied to the empty double precision array will return the empty character vector, which is not a file name that you will be able to audioread(). num2str() applied to a character vector will return the same character vector, by accident.
Then you audioread() what you got back, but you do not pay attention to the directory information that was returned by uigetfile(). The audioread() is going to fail unless the user happened to choose something from the current directory.

댓글을 달려면 로그인하십시오.

채택된 답변

Aditya Verma
Aditya Verma 2020년 6월 25일
Hi!
You can check out MATLAB Coder, it allows you to generate C/C++ code from MATLAB code. However it doesn't support all MATLAB language features/functionalities. You can check the same from here:
Thanks

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by