Borrar filtros
Borrar filtros

how can i convert following script into c coding

3 visualizaciones (últimos 30 días)
Ahmed Hassan Sher
Ahmed Hassan Sher el 24 de Jun. de 2020
Comentada: Walter Roberson el 25 de Jun. de 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 comentario
Walter Roberson
Walter Roberson el 25 de Jun. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Aditya Verma
Aditya Verma el 25 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Audio Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by