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
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.
답변 (1개)
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
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!