フィルターのクリア

How to pass this signal in time to frequency?

1 回表示 (過去 30 日間)
Amanda Botelho Amaral
Amanda Botelho Amaral 2021 年 12 月 21 日
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 Center および File ExchangeMeasurements and Testbenches についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by