"jimosoto" <
[email protected]> wrote in message
news:
[email protected] ...
> I'm really new to Matlab, I've been trying to write a code that windows a
> function with a user-specified window size. The only problem is it isn't
> always and exact fit. To fix this I've written a for-loop that will
> hopefully zero pad the signal to fit the window. I can't seem to get the
> thing to actually zero pad, though. Every time I try to enter a positive
> number, or a function that results in a positive number, it gives me a CAT
> error. I"m sure this is trivial and I'm just trying to go about it all
> wrong, but I can't seem to figure it out. Thanks for the help. (the part
> I'm having trouble with is the part after zeros)Code below:
>
> function y = tester(filename,winLength,overlapLength)
>
> x = wavread(filename);
> lengthx = length(x);
> y = [];
>
> for j = (1:winLength-overlapLength+1:lengthx);
> if (j+winLength-overlapLength < lengthx)
> wy = hanning(winLength).* x(j:winLength+j-1);
> else
> zpx = [x,zeros(1,part I'm having trouble with)];
> wy = hanning(winLength).* zpx(j:winLength+j-1);
> end
> end
>
This seems a little strange to me but OK....
You want to specify a window of length WinLength and apply it to data "x",
yes?
Actually, the code looks like you want to do a sliding window over the data,
yes?
You have something called overlapLength that's not defined anywhere. Are we
supposed to just figure that out so you don't have to work too hard?
There's not a clue. I'll assume that it's smaller than windowLength just for
fun.
I'll assume that lengthx is >> windowLength and that overlapLength is
something like windowLength/2 or /4.
For lengthx=100, windowlength=32 and overlaplength=8
for j = (1:25:100);
j=1
> if (25< 100)
> wy = hanning(32).* x(1:32);
j=25
> if (49< 100)
> wy = hanning(32).* x(25:56);
j=49>
if (73< 100)
> wy = hanning(32).* x(49:80);
j=73
if (97<100)
> wy = hanning(32).* x(73:104); Looks like trouble here!!!
x(104) isn't defined is it?
j = 97
> if (121< 100)
> else
> zpx = [x,zeros(1,??????)];
> wy = hanning(32).* zpx(97:128);
> end
> end
It looks like the trouble is your test
> if (j+winLength-overlapLength < lengthx)
it might be better
if(winLength+j-1)>lengthx
or something like that....
Fred