how to import an audio file ?

169 visualizaciones (últimos 30 días)
jérôme TAÏEB
jérôme TAÏEB el 29 de Sept. de 2018
Respondida: Sukanya el 24 de Dic. de 2024
Hi,
I would like to write that in the command windows:
load handel.mat
filename = 'handel.mp3';
audiowrite(filename,y,Fs);
clear y Fs
[y,Fs] = audioread('handel.mp3');
but i don't know to import my audio file 'handel.mp3' from my hard disk to Matlab.
Can you help me?
thanks

Respuesta aceptada

Stephen23
Stephen23 el 29 de Sept. de 2018
Editada: Stephen23 el 29 de Sept. de 2018
Use audioread. Why do you think that your code is not working? What do you expect to happen?
  2 comentarios
jérôme TAÏEB
jérôme TAÏEB el 29 de Sept. de 2018
Movida: DGM el 21 de Mayo de 2024
the problem is the path of the audio file.
Does Matlab recognize the path of the audio file on the hard disk?
for example,in the following line:
[y,Fs] = audioread('handel.mp3')
if path of 'handel.mp3' is for example C:/Users/chemin1/chemin2,must i write:
[y,Fs] = audioread('C:/Users/chemin1/chemin2/handel.mp3')?
Marcus Niklasson
Marcus Niklasson el 7 de Dic. de 2021
Movida: DGM el 21 de Mayo de 2024
audioread("C:/Users/chemin1/chemin2/handel.mp3")

Iniciar sesión para comentar.

Más respuestas (1)

Sukanya
Sukanya el 24 de Dic. de 2024
% Check if the file exists
if exist('C:\Users\sukan\Downloads\POCORINGTONE.wav', 'file') ~= 2
error('Audio file not found! Place the file in the current folder or specify the correct path.');
end
Audio file not found! Place the file in the current folder or specify the correct path.
% Load the audio file
[audio, fs] = audioread('C:\Users\sukan\Downloads\POCORINGTONE.wav'); % Replace with full path if needed
% Ensure the audio signal is a column vector
audio = audio(:, 1); % Use only the first channel if stereo
% Play the original audio
sound(audio, fs);
disp('Playing the original audio...');
pause(length(audio) / fs); % Wait for the audio to finish
% Resample the audio to match the filter's sampling frequency (100 Hz)
audio_resampled = resample(audio, 100, fs);
fs = 100; % Update the sampling frequency to 100 Hz
% IIR Filter Design
[b_iir, a_iir] = butter(4, 4/(fs/2), 'low');
% FIR Filter Design
numtaps = 50; % Filter order + 1
b_fir = fir1(numtaps-1, 4/(fs/2), 'low');
% Apply Filters to the Resampled Audio
filtered_audio_iir = filter(b_iir, a_iir, audio_resampled);
filtered_audio_fir = filter(b_fir, 1, audio_resampled);
% Play the Filtered Audio Signals
% IIR Filtered Audio
sound(filtered_audio_iir, fs);
disp('Playing the IIR filtered audio...');
pause(length(filtered_audio_iir) / fs);
% FIR Filtered Audio
sound(filtered_audio_fir, fs);
disp('Playing the FIR filtered audio...');
pause(length(filtered_audio_fir) / fs);
% Save the Filtered Audio as Files
audiowrite('filtered_audio_iir.wav', filtered_audio_iir, fs);
audiowrite('filtered_audio_fir.wav', filtered_audio_fir, fs);
disp('Filtered audio files saved: filtered_audio_iir.wav and filtered_audio_fir.wav');
% Time Vector for Plotting
t = (0:length(audio_resampled)-1)/fs;
% Plot the Signals in Time Domain
figure;
subplot(3, 1, 1);
plot(t, audio_resampled);
title('Original Audio Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3, 1, 2);
plot(t, filtered_audio_iir);
title('IIR Filtered Audio Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3, 1, 3);
plot(t, filtered_audio_fir);
title('FIR Filtered Audio Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Analyze Frequency Spectrum
N = length(audio_resampled);
freq = (0:N-1)*(fs/N); % Frequency vector
% FFT for Frequency Analysis
fft_audio = abs(fft(audio_resampled))/N;
fft_audio_iir = abs(fft(filtered_audio_iir))/N;
fft_audio_fir = abs(fft(filtered_audio_fir))/N;
% Plot Frequency Spectra
figure;
plot(freq, fft_audio, 'k', 'DisplayName', 'Original'); hold on;
plot(freq, fft_audio_iir, 'r', 'DisplayName', 'IIR Filtered');
plot(freq, fft_audio_fir, 'b', 'DisplayName', 'FIR Filtered');
xlim([0 50]); % Focus on 0-50 Hz
legend;
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Spectrum Comparison');

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by