Shane Yost
Shane Yost

Reputation: 231

Plotting my .wav file in the time domain instead of freq. domain in MATLAB?

I'm writing a Matlab program to perform a convoluted sum of two signals. I first started out creating a simple sinusoidal signal and a carrier signal. I convoluted the two and created the convoluted signal. You can see that my (x) axis is specified in the time domain. My code and a screen shot of my plot is shown below for clarity.

MY CODE:

note: This program doesn't use the .wav file and instead uses a simple sinusoidal signal.

mySignalFreq = 1E3;
%T = 1/f;
T = 1/mySignalFreq;
tmin = 0;
tmax = 5*T;%i want to graph 5 time periods
dt = T/60;%used 60 to specify spaceing of time domain
t = tmin:dt:tmax;
myCarrierFreq = 560E3;
Bandwidth = 10E3;
omega_mySignal = 2*pi*mySignalFreq;%determine angular frequency
omega_myCarrier = 2*pi*myCarrierFreq;%determine angular frequency
modIndex = 0.8;%modulation index
myCarrierAmp = 4.0;%amplitude of carrier signal
ys = sin(omega_mySignal*t);
yc = sin(omega_myCarrier*t);
convSum = myCarrierAmp*(1+modIndex.*ys).*yc;%Convolution Sum
%create txt file with Write permissions
convolutionData.txt = fopen('convolutionData.txt','w');
%7.5 specifies 7digits and 5digits to the right of decimal
%have to use \r\n for readability
%array of values need to be in [x;y1;y2;y3] format
%comma in the function denotes the seperator
fprintf(convolutionData.txt,'%7.5f,%7.5f,%7.5f,%7.5f\r\n',[t;ys;yc;convSum]);
%close out file
fclose(convolutionData.txt);
%creating a basic plot of all three signals
plot(t,ys,'r',t,yc,'g',t,convSum,'b');
title('Convoluted Signal');
xlabel('Time Periods');
ylabel('Amplitude (Volts)');
grid on;

This is the picture of the plot above. You can see that i'm using the variable 't' as my x axis data.

Plot

I have finally figured out some code that plots my .wav file i created with a recorder. However, it's plots it in the frequency domain. As you can see in the code i'm reading the data in the .wav file into what I'm understanding is an array. Not quite understanding this part so if someone could explain more on that as a side note that would be great.

My main question is how do I incorporate the data from my .wav file into my original code above so it can be plotted in the time domain like my plot above? Just can't figure that part out because the code below is just doing it in the frequency domain.

Here is the code and plot of the .wav file

[wave,fs]=audioread('myvoice1.wav');
t=0:1/fs:(length(wave)-1)/fs;
subplot(2,1,1);
plot(t,wave);
n=length(wave)-1;
f=0:fs/n:fs;
wavefft=abs(fft(wave));
subplot(2,1,2);
plot(f,wavefft);

image

Upvotes: 0

Views: 1026

Answers (1)

Dani Gehtdichnixan
Dani Gehtdichnixan

Reputation: 1285

The upper subfigure in your last plot already is the right signal, so the t and wave are the right variables. Only the second subfigure in your last plot is the frequency domain (represented in the wavefft variable).

Just use the wave variable and you should have what you want.

Upvotes: 0

Related Questions