how can i convert following script into c coding

2 次查看(过去 30 天)
[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