Junfei Wang
Junfei Wang

Reputation: 578

Scaling the plot in matlab

I have a wav file, I import it into matlab, and recovered the original signal from sampled data using the following function:

sub1=wavread('jamming.wav');
 magnSub1=abs(fft(sub1));
 phaseSub1=angle(fft(sub1));
 sub1_L=magnSub1.*exp(i*phaseSub1);
 sub1_L=ifft(sub1_L);
 q=(2^15-1)*(abs(sub1_L).*cos(angle(sub1_L)));
 plot(q);
 axis([44000,45000,-2^15+1,+2^15-1]);

But now I want to add some scatter plot on the existing graph to compare the sampled data and continuous wave. It is what i have so far:

[wave,fs]=wavread('jamming.wav'); 

sound(wave,fs);

t=0:1/fs:(length(wave)-1)/fs;
z = t([1],:);
wave1=wave(:,[1]);
scatter(z,wave1);

The problem is that I cannot scale the x-axis to the first graph. Can someone help me with this issue? My final graph should be the same with the one in this page :http://www.cheers4all.com/2012/07/analog-to-digital-convertor-matlab-source-code/

Help will be really appreciated, thank you in advance!

Upvotes: 0

Views: 827

Answers (1)

Ryan J. Smith
Ryan J. Smith

Reputation: 1140

The problem here is that your first plot is plotted over the range 1:length(q) while the second plot is being plotted over the range 0 : 1/fs : (length(wave)-1)/fs

Assuming your values q and wave1 are the same length (and it looks like they might be), try:

figure; hold all;
plot(z, q);
plot(z, wave1);

You can then adjust the line properties of each of the plot commands to your liking.

If q and wave1 are not exactly the same length, a quick and dirty fix would be:

figure; hold all;
plot(1:length(q), q);
plot(1:length(wave1), wave1);

This probably won't give you exactly what you're looking for, but it should be a step in the right direction.

Upvotes: 0

Related Questions