Ho usato il seguente codice Matlab:
- Codice:
clear all
close all
clc
Fs = 30000;
Ts = 1/Fs;
t = 0 : 1/Fs : 1/50 - 1/Fs;
theta = 2*pi*50*t;
Xt = i1;
%Transformation
n = 2^nextpow2(length(Xt));
Y=fft(Xt,n); %FFT
df=Fs/length(Y); %frequency resolution
f=(0:1:length(Y)/2)*df; %frequency axis
figure
subplot(3,1,1);
M=abs(Y)/length(Xt)*2; %amplitude spectrum
M_rounded = int16(M(1:size(f, 2))); %Limit the frequency range
ind = find(M_rounded ~= 0);
stem(f(ind), M(ind), 'LineWidth', 0.5);
xlim([0 350]);
grid on;
xlabel('Frequency (Hz)')
ylabel('Magnitude');
subplot(3,1,2);
P=angle(Y)*180/pi; %phase spectrum (in deg.)
stem(f(ind), P(ind), 'LineWidth', 0.5);
xlim([0 350]);
ylim([-100 100]);
grid on;
xlabel('Frequency (Hz)');
ylabel('Phase (degree)');
subplot(3,1,3)
plot(t,i1)
Ma il risultato è palesemente sbagliato. Qualcuno saprebbe aiutarmi a trovare l'errore? Se mi suggerite un metodo, cerco di allegare anche il file.mat