Plotting Average Spectra Plot using MATLAB - matlab

I have four 1xN sound signals and I want to view the average spectra plot like the one given in the link below:
http://i1233.photobucket.com/albums/ff396/sakurayen/Plot/AMaximumLikelihoodApproachtoSinglechannelSourceseparationpdf-AdobeReader.jpg
I've tried to use the MATLAB function , PSD, to plot the spectral but I am getting a different plot instead. Note that the data used for both the plots are the same.
plot obtained using PSD function in MATLAB:
http://i1233.photobucket.com/albums/ff396/sakurayen/Plot/PowerSpectralDensityofRJMF.png
Thanks!

Related

How to Calculate the transfer function and plot it after making fourier transform in frequency domain in terms of magnitude and phase?

I have a trouble of plotting the transfer function in terms of magnitude and phase after making the Fourier transform of two signals.
First, I have used excel xlxs to read the column to plot in time domain and frequency domain, then I calculate the transfer function and this goes fine.
But for magnitude and phase, I have trouble for plotting them. I tired to plot them, but this is totally incorrect. Would someone help me with this?
Here is the code and excel file also.
solarcell1 = xlsread('solarcell.xlsx','A2:C100005');
t=solarcell1(:,1);
N=length(t);
Channel1V = solarcell1(:,2);
Channel2V = solarcell1(:,3);
sig1=Channel1V;
sig2=Channel2V;
fs=1/((solarcell1(3)-solarcell1(2))*1e-3);
FA1=fs/length(sig1);
FA2=fs/length(sig2);
frange1=-fs/2:FA1:fs/2-FA1;
frange2=-fs/2:FA2:fs/2-FA2;
subplot(3,2,1);
plot(t,sig1);
hold on
plot(t,sig2);
title('Input and Output of Solar cell');
xlabel('Time');ylabel('Amplitude');
subplot(3,2,2);
plot(t,sig2);
title('Output');
xlabel('Time');ylabel('Amplitude');
z1=fftshift(fft(sig1))/length(t);
subplot(3,2,3);
plot(frange1,abs(z1));
title('Input');
xlabel('Freq.');ylabel('Amplitude');
z2=fftshift(fft(sig2))/length(t);
subplot(3,2,4);
plot(frange2,abs(z2));
title('Output');
xlabel('Freq.');ylabel('Amplitude');
TFC=z2./z1;
magnitude=20*log(abs(TFC));
phase=atan2(imag(TFC),real(TFC));
subplot(3,2,5);
bode(frange1(1002:N),magnitude(1002:N));
title('Magnitude');
xlabel('Freq.');ylabel('Magnitude');
subplot(3,2,6);
semilogx(frange1(1002:N),phase(1002:N));
title('Phase');
xlabel('Freq.');ylabel('Phase');
I can see three issues in the code you provided.
First, your usage of bode is incorrect. This function takes a dynamic model system as argument, and you gave two vectors frange1(1002:N)and magnitude(1002:N). For now, I suggest you simply use plot instead.
subplot(3,2,5);
plot(frange1(1002:N),magnitude(1002:N));
title('Magnitude');
xlabel('Freq.');ylabel('Magnitude');
Then, your usage of semilogx is also risky when you have negative values for the x-axis. With frange1=-fs/2:FA1:fs/2-FA1; you shouldn't ask for semilogx of it. For now, I suggest plot.
Finally, I suggest you use unwrap to plot the phase.
subplot(3,2,6);
plot(frange1(1002:N),unwrap(phase(1002:N)));
title('Phase');
xlabel('Freq.');ylabel('Phase');
It plots:

ftt data for waterfall plot

I used periodogram in Matlab to perform vibration analysis. I wanted to see how the frequencies changed with time during vibration, and I believed I should use waterfall plot or other 3D plot. My question is how I can save the amplitude data from ftt into a matrix (m,n). m is number of the data point from each calculation, n is the number of time interval for each calculation with periodogram.
I learned how to plot waterfall plot or other 3D plot in Matlab, but do not know how to save the amplitude data into a matrix. Did some search, but with no luck.

How to export fitted curve to 1D vector

With the use of Curve Fitting toolbox I'm fitting to 11 data points a curve described by a custom equation. As a result I get something like this:
I want to save 1D vector represented bye the red line on the plot above into a matlab variable. I try to use Fit->Save to Workspace... option from the Curve Fitting toolbox menu, but saved variables do not contain any of the fitted data.
How can I save fitted data into matlab variable?
The saved MATLAB-object (default name is fittedmodel) contains the fitted function as a function-handle and the fitted coefficients corresponding to this function-handle. You can then evaluate at the data points of your choice with feval.
In the following example the fitted function will be evaluated at the original datapoints x:
y = feval(fittedmodel, x);
Now you can directly plot the result:
plot(x,y);

setting the x-axis when plotting convolution in matlab

i am plotting a convolution in matlab for that purpose i create 2 arrays representing the values of the functions in various points.
x=[1:1000];
c=[1:1000];
t = linspace(-18,18,1000);
for k=1:1000, x(k)=input(t(k));
c(k)=h(t(k));
end;
plot(conv(c,x));
the thing is that it plots the conv against the place of the answer in the array.
i want to plot the conv against the 'n' that will give the value.
plotting against t,c or x from the example above does not give the righ answer. also the plot here is of length 1999.
creating a linspace of length 1999 will plot but it wont give the right answer.
any suggestions?

How can I display empirical pdf of my 100x1 vector data in Matlab?

I have a data which is 100x1 vector. How can I display its empirical pdf in Matlab? Also, if I want to compare the pdf of three vectors on the same graph, then how to do that?
Right now I am using pdfplot.m file to plot my empirical pdf, however when I want to compare the 3 distributions by using 'hold on', then firstly its not working and secondly all the distributions are in same color. Thanks!
EDIT: I don't want to plot cdf.
What you are looking for is Kernel density estimation (also known as Parzen windows). Its implemented in KSDENSITY function in the Statistics toolbox:
data = randn(100,1);
ksdensity(data)
The Wikipedia entry above has a MATLAB example using a function submission on FEX
hist:
hist(data)
or, if you want more control over how it is presented, use:
[n,x] = hist(data);
plot(x,n,'rx-'); %# just an example, plot the pdf with red x's and a line,
%# instead of bars
figure;
plot(x, cumsum(n)/sum(n)); %# plot the CDF