how can i convert following script into c coding

2 views (last 30 days)
[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 Comment
Walter Roberson
Walter Roberson on 25 Jun 2020
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.

Sign in to comment.

Accepted Answer

Aditya Verma
Aditya Verma on 25 Jun 2020
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

More Answers (0)

Categories

Find more on Audio Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!