How to use circshift in Matlab? What am I doing wrong?
I would like to plot the "greasy" test signal in Matlab, and then plot a Gauss function in the same plot. The script below does that.
But I would like to be able to place the Gauss function at a certain position, so I see that others often use CIRCSHIFT to move plots.
When I use it I can move the Gauss function to the left or right, but not up and down.
PGAUSS used in the script comes from the LTFAT DSP third party toolbox, but it could for debugging be any function. E.g.开发者_运维知识库 -x^2.
Can someone figure out, what I am doing wrong?
Here is how it looks with [0 0] alt text http://img268.imageshack.us/img268/1130/66837635.png
Here is how it looks with [0 111] alt text http://img684.imageshack.us/img684/2386/0111q.png
Here is how it looks with [111 0] alt text http://img194.imageshack.us/img194/8760/1110d.png
Lots of love, Louise
g = greasy;
fs = 16000;
Lg = length(g);
% -2441 so just get the first 500 points
L2 = floor(Lg/2)+1 - 2441;
gf = greasy;
gf = gf(1:L2);
hold on
plot (1:L2,gf);
xlabel('Time / samples');
ylabel('Amplitude');
% Contructing values to make the plot look as desired
L = 500;
tfr = 1;
cent = 300;
%gw = pgauss(L,tfr,cent)
% Here I would have expected the Gauss function to be
% moved down, but nothing happens.
gw = circshift(pgauss(L,tfr,cent), [0 -1]);
plot(gw,'Color','red');
% Multiply the signal with the Gauss window
figure(2);
plot(gf.*gw);
What you want to do is to add a constant factor to Gauss function to move it up or down.
B = [1,2,3,4,5]
B =
1 2 3 4 5
size(B)
ans =
1 5
circshift(B,[2 0])
It does nothing because B has only one row, so this row returns to its original position regardless of value of rowshift
ans =
1 2 3 4 5
circshift(B,[0 2])
ans =
4 5 1 2 3
B + 5
ans =
6 7 8 9 10
If you want it moved down you have to use [1, 0] not [0, -1]
Take a look at this
A = [1,2,3; 4,5,6; 7,8,9]
A =
1 2 3
4 5 6
7 8 9
circshift(A,[0 -1])
ans =
2 3 1
5 6 4
8 9 7
circshift(A,[1 0])
ans =
7 8 9
1 2 3
4 5 6
If pgauss(L,tfr,cent) is a column vector then ofcourse circshift(a, [0 X]) for any X won't change it, because it rotates on the second dimention which is 1.
If you want to move the gaussian upward in the graph, you have to add a number to it:
gw = pgauss(L,tfr,cent) - 1;
精彩评论