How to pass this signal in time to frequency?
1 view (last 30 days)
Show older comments
I need to pass this signal in time to frequency. A frequency range of interest is from 100Hz to 2MHz. I did the following code, but the answer doesn't come out as expected. Could someone tell me the error?
C=corrente_at_500;
V=tensao_at_500;
n = length(t);%NUMERO DE AMSTRAS
tmax = t(end);%TEMPO TOTAL DA SIMULAÇÃO
T = tmax*1.0;%TEMPO MÁXIMO DA SIMULAÇÃO = TMAX
c = -log(0.001)/T; %VARIAVEL AUXILIAR
dt = T/n;%INTERVALO NO TEMPO
dw = 2*pi/(n*dt);%INTERVALO NA FREQ.
kk = 0:n/2;
s= (-1i*c + dw*kk)./1000;
%Sinal
C= Z_5T_150;% Sinal no tempo para análise
xlen = length(C);
% Janelamento
xwin = flattopwin(xlen, 'periodic');
% Calculo do tamanho da janela coerente
Cx = sum(xwin)/xlen;
% FFT do sinal
L = length(V);
px = nextpow2(10*xlen);
nfftx = 2^px;
X = fft(C, nfftx);% X = fft(x.*hamming(xlen), nfftx);
Y = fft(V, nfftx);% X = fft(x.*hamming(xlen), nfftx);
Z=Y./X;
2 Comments
Tyler F
on 21 Dec 2021
You didnt provide the V signal. Can you provide more details on what you were expecting? The signal you are taking the FFT of does not have much frequency content.
Answers (1)
Tyler F
on 21 Dec 2021
Edited: Tyler F
on 21 Dec 2021
Assuming t is a vector of time stamps, dt is your sampling time, to get a "proper" fft plot I would add this to the end of your script;
fs = 1/dt;
f = fs*(0:(nfftx/2))/nfftx;
XdB = 10*log10(abs([X(1) 2*X(2:nfftx/2+1)']./nfftx));
figure
plot(f,XdB)
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
fs is your sampling frequency
f is the vector of frequency points in your fft
XdB is the real magnitude of your signal. The matlab fft() function returns the complex DFT which is mirrored for a real input signal, so we are only taking the first half of it. Because the signal is mirrored, we need to multiple all of the sample points that are mirrorer (everything except zero) by 2. Then we scale the value by the number of sample points, take the magnitude, convert to dB, and plot it.
8 Comments
Tyler F
on 21 Dec 2021
Remove all of the spaces except the one between X(1) and 2. Not sure why it inserted spaces if you copy/pasted.
XdB = 10*log10(abs([X(1) 2*X(2:nfftx/2+1)']./nfftx)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!