How to pass this signal in time to frequency?

1 次查看(过去 30 天)
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 个评论
Tyler F
Tyler F 2021-12-21
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.
Amanda Botelho Amaral
I have put in the original data now. I think it will be easier to understand.

请先登录,再进行评论。

回答(1 个)

Tyler F
Tyler F 2021-12-21
编辑:Tyler F 2021-12-21
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 个评论
Tyler F
Tyler F 2021-12-21
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)
Amanda Botelho Amaral
I modified my code using your suggestions. The answer comes out almost similar to what I expect, but mirrored. Any idea what it might be?
C = corrente;% n = length(t);%NUMERO DE AMOSTRAS
V = tensao;
Cinput_freq = fft(exp(-c*tfreq).*C)*dt;
Vinput_freq = fft(exp(-c*tfreq).*V)*dt;
% %SINGLE-SIDED AMPLITUDE
Cinput_freq = Cinput_freq(1:n/2+1);
Cinput_freq(2:end-1) = 2*Cinput_freq(2:end-1);
%SINGLE-SIDED AMPLITUDE
Vinput_freq = Vinput_freq(1:n/2+1);
Vinput_freq(2:end-1) = 2*Vinput_freq(2:end-1);
Za = Vinput_freq./Cinput_freq;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by