how can i convert following script into c coding

3 vues (au cours des 30 derniers jours)
Ahmed Hassan Sher
Ahmed Hassan Sher le 24 Juin 2020
Commenté : Walter Roberson le 25 Juin 2020
[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 commentaire
Walter Roberson
Walter Roberson le 25 Juin 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.

Connectez-vous pour commenter.

Réponse acceptée

Aditya Verma
Aditya Verma le 25 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Audio Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by