- Assumes the audio is mono for simplicity. If your audio is stereo, you will need to handle both channels separately or convert it to mono.
- The normalization step converts audio samples to the range of 16-bit integers. This is because dec2bin works on integers. If your audio samples use a different bit depth, adjust the normalization accordingly.
- Ensure that the audio file path 'your_audio_file.wav' is correctly specified and that the output file 'reconstructed_audio.wav' is being saved to a location you have write access to.
- Directly converts the entire audio file to binary and back. For an actual communication system, you would need to consider the transmission method, error handling, and possibly encoding/decoding techniques to ensure reliable communication.
i want convert recorded audio file to binary.
조회 수: 66 (최근 30일)
이전 댓글 표시
hey, Im doing project in communication system . In which i have to transmit audio and then recieve the audio , so i want to convert the audio file to binary and then at reciever side i need to convert binary to audio.so i need matlab code for the same
댓글 수: 0
채택된 답변
Hassaan
2024년 2월 23일
% --- Audio to Binary ---
[audio, fs] = audioread('your_audio_file.wav'); % Load your audio file here
audio_normalized = int16(audio * 32767); % Normalize
audio_binary = dec2bin(typecast(audio_normalized(:), 'uint16'), 16); % Convert to binary
binary_vector = audio_binary(:)'; % Reshape to vector for transmission
% --- Binary to Audio ---
binary_matrix = reshape(binary_vector, [], 16); % Reshape back to matrix
audio_integers = bin2dec(binary_matrix); % Convert binary to decimal
audio_reconstructed = typecast(uint16(audio_integers), 'int16'); % Typecast to int16
audio_reconstructed_normalized = double(audio_reconstructed) / 32767; % Normalize to [-1, 1]
% Save the reconstructed audio
audiowrite('reconstructed_audio.wav', audio_reconstructed_normalized, fs);
% --- Optional: Play Original and Reconstructed Audio for Comparison ---
sound(audio, fs); % Play original audio
pause(length(audio)/fs + 1); % Wait for audio to finish plus a little extra
sound(audio_reconstructed_normalized, fs); % Play reconstructed audio
Notes
댓글 수: 1
Walter Roberson
2024년 2월 23일
[audio_normalized, fs] = audioread('your_audio_file.wav', 'native'); % Load your audio file here
and
audio_reconstructed_normalized = typecast(uint16(audio_integers), 'int16'); % Typecast to int16
The audio functions are willing to work directly on int16
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!