transformer une variable local en global d'une fonction
Bonjour,
on m'a passé une fonction qui me trace la densité spectrale de puissance d'un signal.
J'aimerai avoir accès au valeur de la courbe, mais c'est impossible. Comment modifier ma fonction pour avoir accès au cordonnée des point de la courbes svp.
Merci:D
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| function plotfft(y,fs,plotstring,plotneg,n,zdb,dr)
global f;
if size(y,1) > 1
y = y';
end
N = length(y); % N is the number of points of y, whereas n is the number of points of the FFT
if nargin < 2
fs = 1;
end
if nargin < 3
plotstring = 'b';
end
if nargin < 4
plotneg=0;
end
if nargin < 5 || isempty(n)
n = N;
end
if nargin < 6
zdb = false;
end
if nargin < 7
dr = [];
end
% n = floor(n/2)*2+1; % we want n odd to have F(0);
y = y' .* hann(N);
Y = fftshift(fft(y,n));
Y = 2/N*Y;
f = fs * (-0.5+1/n/2:1/n:0.5-1/n/2);
if zdb
Y = Y./max(abs(Y))./sqrt(2)*0.999;
end
if plotneg
plot(f,20*log10(abs(Y)),plotstring);
else
plot(f(round(end/2+0.5:end)),20*log10(sqrt(2)*abs(Y(round(end/2+0.5:end)))),plotstring);
end
if not(isempty(dr))
a = axis;
axis([a(1:2),a(4)-dr,a(4)]);
end
grid on;
xlabel('Frequency (Hz)');
ylabel('|S^2(f)| (dBW)');
A=f(round(end/2+0.5:end)) |