FFT with non sinusoidal signal

3 visualizaciones (últimos 30 días)
Edoardo Matteo Marchica
Edoardo Matteo Marchica el 27 de Mzo. de 2018
Editada: Stephan el 23 de Abr. de 2018
Hi, I have to obtain the frequency analysis of a discrete time signal (current). I'll attach .mat of this signal.
The code I used is the following:
clear all
close all
clc
Fs = 10000;
Ts = 1/Fs;
t = 0 : 1/Fs : 2*pi/(2*pi*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)
And it does not work. Can someone help me?
PS: sorry for my bad english

Respuestas (1)

Stephan
Stephan el 23 de Abr. de 2018
Editada: Stephan el 23 de Abr. de 2018
Hello,
When the code starts, you run the following command:
clear all
This command deletes your data in the Matlab workspace. Nowhere in your code do you import the .mat file of your signal. So there is nothing that the code can do due to missing data ...
Either you do it this way (provided you have previously inserted the data in the Matlab workspace):
%clear all
or you type an additionally line of code after your 3 cleaning-commands as follows:
load ('name_of_your_data_file.mat')
whatever the name of your file is.
After doing that, the data is loaded into the Matlab workspace and your code works on my Matlab.
best regards
Stephan

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by