Matlab Signal processing

johndoe45

Joined Jan 30, 2010
364
alright so that is sampling rate of 44.1 kHz.

therefore time between samples is 1/sampling rate

plot(1/tdata,2*smoothData,1/tdata,abs(cdata)) should put in terms of time

INCORRECT

did you make up these functions???

Going to bed. Sorry have headache. Had test today. Did three homework assignments. Got two more to do when i wake up. And two labs due on Friday. :(
 
Last edited:

johndoe45

Joined Jan 30, 2010
364
function [data,fs,smoothData] = Uload()

[filename, pathname] = uigetfile('*.wav','Select Data File');



if filename ~= 0

cd(pathname);

% Get data and sampling rate

[data,fs] = wavread([pathname filename]);

% length(data)
% fs
data = data/max(data:) ));
hwin1 = subplot(221);
ldata = length(data);
tdata = 1:ldata;
cdata = hilbert(data);
[b,a] = butter(5,20/(fs/2),'low');
smoothData = filtfilt(b,a,abs(hilbert(data)));
plot(tdata,2*smoothData,tdata,cdata)
xlabel('Samples')
ylabel('Signal (Volts)')
legend('Envelope','Signal')
hwin2 = subplot(222);

% [b,a] = butter(5,20/(fs/2),'low');
% smoothData = filtfilt(b,a,abs(hilbert(data)));
% plot(smoothData)
p = fft(data);
ls = length(p);
x=abs(p((1:ceil(ls/2))));
plot(hwin2,x)


% if min(size(data))>1
% error('Can''t load stereo data')
% end

end
 
Last edited:

johndoe45

Joined Jan 30, 2010
364
what is your second plot????

it isn't even on http://cnx.org/content/m14198/latest/

what i did in previous post is put labels on graph. had them in wrong place. and took off absolute in abs(cdata) and added legend

a way to analyze this if this is your project would be to first find where the first wave starts which is when 2*smoothData is > around 0.2 just to be safe. then find the maximum height until 2*smoothData gets back to 0.2.

then plot a vertical line and that is where the vowel is. For the Low threshold Envelope Detector. Taaaa Daaaaa!!!!
 
Last edited:

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
what is your second plot????

it isn't even on http://cnx.org/content/m14198/latest/

what i did in previous post is put labels on graph. had them in wrong place. and took off absolute in abs(cdata) and added legend

a way to analyze this if this is your project would be to first find where the first wave starts which is when 2*smoothData is > around 0.2 just to be safe. then find the maximum height until 2*smoothData gets back to 0.2.

then plot a vertical line and that is where the vowel is. For the Low threshold Envelope Detector.
Taaaa Daaaaa!!!!
Yeah , this is what i'm looking for .
I got no problem finding the start point right now. M struggling getting the lower threshold:(
 

johndoe45

Joined Jan 30, 2010
364
just tell it from sample something to sample something. calculate max with some function. i don't know it.

why do you have 2*smoothData and not just smoothData
 

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
just tell it from sample something to sample something. calculate max with some function. i don't know it.

why do you have 2*smoothData and not just smoothData
Is optional , you can do it "2*smoothData" or "smoothData".


and perhaps you can help me to interpret this .
I use it to type on command window
>> figure
>> plot(smoothData>0.3, 'r')
>> [mx,el]=max(smoothData>0.3)
>> hold off
>> plot(smoothData)
>> hold on
>> plot(diff(smoothData>0.3)==1,'r')
 

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
'r' gives you a red plot
like 'g' gives you a green plot etc

HOLD ON holds the current plot and all axis properties so that
subsequent graphing commands add to the existing graph.
HOLD OFF returns to the default mode whereby PLOT commands erase
the previous plots and reset all axis properties before drawing
new plots.
HOLD, by itself, toggles the hold state.
HOLD does not affect axis autoranging properties.
 

johndoe45

Joined Jan 30, 2010
364
TRY THIS

GOING TO NEED TO CHANGE
YofPeaks(2)
EVERYTIME TO WHICHEVER PEAK (N) YOU NEED!!!!!!

TO ZOOM IN TO PLOT, ADD
axis([xmin xmax ymin ymax])

TO THE VERY BOTTOM!!!!!!

[filename, pathname] = uigetfile('*.wav','Select Data File');

if filename ~= 0

cd(pathname);

% Get data and sampling rate

[data,fs] = wavread([pathname filename]);

% length(data)
% fs
data = data/max(data:) ));
xlabel('Samples')
ylabel('Signal (Volts)')
ldata = length(data);
tdata = 1:ldata;
cdata = hilbert(data);
[b,a] = butter(5,20/(fs/2),'low');
smoothData = filtfilt(b,a,abs(hilbert(data)));

%this part is kind of like a limiter to get rid of the waves. Just for fun
%to try and make things easier for me to read : ) Probably want to delete this though unless you like it

for i=1:length(data)-1
if smoothData(i) < .09
smoothData(i)=0;
if cdata(i) < .09
cdata(i)=0;
end
end
end

%find out the maximum of each peak. found this somewhere online


delta=1/length(tdata);
maxtab = [];
mintab = [];

smoothData = smoothData:) ); % Just in case this wasn't a proper vector

if nargin < 3
tdata = (1:length(smoothData))';
else
tdata = tdata:) );
if length(smoothData)~= length(tdata)
error('Input vectors v and x must have same length');
end
end

if (length(delta:) )))>1
error('Input argument DELTA must be a scalar');
end

if delta <= 0
error('Input argument DELTA must be positive');
end

mn = Inf; mx = -Inf;
mnpos = NaN; mxpos = NaN;

lookformax = 1;

for i=1:length(smoothData)
this = smoothData(i);
if this > mx, mx = this; mxpos = tdata(i); end
if this < mn, mn = this; mnpos = tdata(i); end

if lookformax
if this < mx-delta
maxtab = [maxtab ; mxpos mx];
mn = this; mnpos = tdata(i);
lookformax = 0;
end
else
if this > mn+delta
mx = this; mxpos = tdata(i);
lookformax = 1;
end
end
end
end
XofPeaks=maxtab(1:length(maxtab),1)
YofPeaks=smoothData(XofPeaks)
ylim('auto')
plot(tdata,cdata,'Color','blue')
hold on;
plot(tdata,smoothData,'LineWidth',2,'Color','red')
hold on;
line([1 ; length(tdata)],[YofPeaks(2) ; YofPeaks(2)],'Color','black')
 
Last edited:
hi, i dunno how to plot this graph of function t in matlab.Could anyone please help me to have a look..thanx for ur help..=)

clear all;
clc
clf

t=-4:0.001:4;

h=1/t;

plot(t,h);
grid;
xlabel('t ');
ylabel('h(t)');
title('graph for h(t)');
 

johndoe45

Joined Jan 30, 2010
364
should have made your own post. i check everything that says matlab
what is clf??????????????


clear all
clc
clf


t=-4:0.001:4;

h=1./t;

plot(t,h)
grid
xlabel('t')
ylabel('h(t)')
title('graph for h(t)')
 

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
Hey John ,
I'm back for some question again ..
1st just want to ask ,if i call the Uload function in my mainfunction ,
and when i run it , it will the filtered waveform(hilbert's envelope) or without .
 

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
Hey John ,
those files that i sent you plots the fft(frequency domain as well )
Can i ask is it possible to find the mean of the spectrum for example the skewness & kurtosis or is that any other method ?
 

johndoe45

Joined Jan 30, 2010
364
don't understand first question but yes it should run in the main function window.

alright figured it out

type function Uload in your Uload.m file at the TOP!!!!!

then in your main function file. just type Uload wherever you want it to run the Uload.m file.
(this avoids having to copy and paste the Uload.m file into the main function file)

both the main function file and Uload file must be in same directory.
 
Last edited:

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
don't understand first question but yes it should run in the main function window.

alright figured it out

type function Uload in your Uload.m file at the TOP!!!!!

then in your main function file. just type Uload wherever you want it to run the Uload.m file.
(this avoids having to copy and paste the Uload.m file into the main function file)

both the main function file and Uload file must be in same directory.
NonOnon.. i understood that ...
 

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
These are all the questions :
1) There are play buttons on the main function , just want to know if i callback the Uload to the main function play1 , it will play the hilbert transform filtered part ?
2) You see , when you run the main function it will plot the time waveform and its frequency domain. Can i ask what are the methods are to be used to calculate the mean of the time waveform and also for the spectrum . My project suggest that i use skew and kurthosis.
 

johndoe45

Joined Jan 30, 2010
364
i am not a electrical engineer and don't have a lot of experience with waves and frequencies. i don't know what you are talking about with play1 button. as long as play1 has Uload in it i don't see why it wouldn't work. have you tested it out

now to find the mean why don't you just do mean(whatever the y axis is in the time waveform) and that should calculate all the values in the x axis array.

same applies for mean of spectrum
 
Top