Clear Filters
Clear Filters

how to use audiowrite

6 views (last 30 days)
wissal
wissal on 1 May 2024
Commented: Star Strider on 1 May 2024
clear; clc; close all;
data= load('am_data.mat');
d=data.d';
%
ds = d(16000+1:16000+2560);
%
Ds = fftshift(fft(ds));
%
f = ((-2560/2) : (2560/2 - 1)) * 0.100;
plot(f,abs(Ds));
%
T=1/256000;
t=(1:length(d))*T;
fc=-17000;
%
dm=d.*(exp(-1i*2*pi*t*fc))';
%
Dm=fftshift(fft(dm(16000+1:16000+2560)));
%
figure();
plot(f,abs(Dm));
%
th = (-100:100)*T;
h = sin(10000*pi*th + 1e-6)./(10000*pi*th+1e-6);
%
figure()
plot(th,h);
%
dmf = conv(dm,h);
%
Dmf = fftshift(fft(dmf(16000+1:16000+2560)));
figure()
plot(f,abs(Dmf));
%
dmfs = dmf(1:32:end)/max(abs(dmf));
sound(real(dmfs));
pause;
%
sound(abs(dmfs));
%
audiowrite('test.wav',dmfs,256000);

Accepted Answer

Star Strider
Star Strider on 1 May 2024
You did not actually ask a question.
However I get the impression that ‘dmfs’ is complex, and that is not going to work. That argument has to be a (samples x channels) real matrix, so you either need to use:
audiowrite('test.wav',real(dmfs),256000);
or:
audiowrite('test.wav',abs(dmfs),256000);
to get it to work.
If you want to write extra channels with the imaginary or phase information, that is certainly possible.
Something like that might be:
audiowrite('test.wav',[real(dmfs) imag(dmfs)],256000);
or:
audiowrite('test.wav',[abs(dmfs) angle(dmfs)],256000);
For this, ‘dmfs’ must be a column vector.
You can reconstruct it after you read it.
If you want to save a complex vector, it might be easier to just use the save function to save it as a .mat file:
Fs = 256000;
save('dmfs.mat','dmfs','Fs')
.
  2 Comments
wissal
wissal on 1 May 2024
you were right thank you so mush
Star Strider
Star Strider on 1 May 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!