I want to convert a .wav file to binary,modulate it,transmit,demodulate and convert the binary back to .wav file.But I am not able to write binary data back to wav file.

wavdata = audioread('roja.wav');
wavbinary = dec2bin( typecast( single(wavdata(:)), 'uint8'), 8 ) - '0';
orig_size = size(wavdata);
wavb1=uint8(wavbinary);
w1=reshape(wavb1,15486976,1);
xmod=qammod(w1,16,0,'gray');
y1=awgn(xmod,10);
rdmod=qamdemod(y1,16,0,'gray');
% rdmod1=reshape(rdmod,1935872,8);
rdmod2=uint8(rdmod);
data = uint8(bin2dec( char( reshape( rdmod2, 8,[]).'+'0')));
audiowrite(data, 'rec_roja.wav',8000)
Error using bin2dec (line 55)
Binary string may consist only of characters 0 and 1
Error in wavb (line 14)
data = uint8(bin2dec( char( reshape( rdmod2, 8,[]).'+'0')));
also waveread is not working in r2016

6 Commenti

Can you share roja.wav this file, so that we can try on your code?
Delete your comment from answer section, please note this is comment section, you can use google drive and share
Could you decode the error?Is there any problem with audiowrite()?

Accedi per commentare.

 Risposta accettata

Which release are you using? R2016a was the last release that accepted by initial phase (0) and symbol order (gray) for qammod, with R2016b being the last release that permitted initial phase.
In current releases, the default output for qamdemod is integer, and the integers can be anywhere from 0 to M-1 where M is the order you passed (which is 16 in your case). Current releases have an option 'outputtype', 'bit'
But when you qammod(), in current releases the default input is integer as well, and you would need 'inputtype', 'bit' to specify bits.
Which is to say, you are currently telling qammod that your inputs are integers in the range 0 to 15, but it just happens that none of them are anything other than 0 or 1. You then add white noise and decode. But the white noise might happen to knock some of the symbols into a different constellation, so you when you qamdemod you can get back integers other than what you put in.
If you were using modern MATLAB, you would
xmod=qammod(w1, 16, 'gray', 'inputtype', 'bit');
and
rdmod=qamdemod(y1, 16, 'gray', 'outputtype', 'bit');
and the problem with bin2dec would no longer occur.

8 Commenti

In R2016a you should be able to use the calls I show.
clc;
clear all;
close all;
wavdata = audioread('roja.wav');
wavbinary = dec2bin( typecast( single(wavdata(:)), 'uint8'), 8 ) - '0';
orig_size = size(wavdata);
wavb1=uint8(wavbinary);
w1=reshape(wavb1,15486976,1);
% xmod=qammod(w1,16,0,'gray');
xmod=qammod(w1, 16, 'gray', 'inputtype', 'bit');
y1=awgn(xmod,10);
% rdmod=qamdemod(y1,16,0,'gray');
rdmod=qamdemod(y1, 16, 'gray', 'outputtype', 'bit');
rdmod1=reshape(rdmod,1935872,8);
data = uint8(bin2dec( char( reshape( rdmod1, 8,[]).'+'0')));
audiowrite(data, 'rec_roja.wav',8000)
Now the error shows
Error using audiowrite
The value of 'filename' is invalid. Expected input to be one of these types:
char
Instead its type was uint8.
Error in audiowrite>parseInputs (line 226)
parse(p,filename, y, Fs, pvpairs{:});
Error in audiowrite (line 103)
props = parseInputs(filename, y, Fs, varargin);
Error in wavb (line 16)
audiowrite(data, 'rec_roja.wav',8000)
Error using audiowrite>validateFilename (line 323)
Cannot create file rec_roja1.wav. Permission Denied.
Error in audiowrite (line 105)
[props.filename, fileExisted] = validateFilename( props.filename );
Error in wavb (line 17)
audiowrite('rec_roja1.wav',data,8000)
The above error shows
appdata = getenv('APPDATA');
if isempty(appdata)
error('No APPDATA?? Either not a PC or badly configured!');
end
mapp = fullfile(appdata, 'MATLAB');
if ~isdir(mapp)
try
mkdir(mapp);
catch ME
error('Failed to create directory "%s"', mapp);
end
end
mq = fullfile(mapp, 'Q420697');
if ~isdir(mq)
try
mkdir(mq);
catch ME
error('Failed to create directory "%s"', mq);
end
end
outfile = fullfile(mq, 'rec_roja1.wav');
audiowrite(outfile, data, 8000);
fprintf('Your file was saved to: "%s"\n', outfile);

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by