How to pass this signal in time to frequency?

조회 수: 4 (최근 30일)
Amanda Botelho Amaral
Amanda Botelho Amaral 2021년 12월 21일
댓글: Amanda Botelho Amaral 2021년 12월 22일
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
Amanda Botelho Amaral 2021년 12월 21일
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
Amanda Botelho Amaral 2021년 12월 22일
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에서 Measurements and Testbenches에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by