필터 지우기
필터 지우기

Plot Wavelet FFT in Hz

조회 수: 1 (최근 30일)
Alexander Voznesensky
Alexander Voznesensky 2017년 8월 7일
댓글: Robert U 2017년 8월 10일
Hi! I'm trying to do fft of wavelet function. But I'm confused: how to define x-axis f in Hz? Here is my code:
scales=1:100;
wname='db20';
N=10;
[phi, psi, tgrid] = wavefun (wname, N);
f=???
figure;
hold on
plot(f,abs(fft(phi)));
plot(f,abs(fft(psi)));
before, in my practice, i used:
f=0:Fs/(N-1):Fs;
What should I do now?

답변 (2개)

Robert U
Robert U 2017년 8월 8일
편집: Robert U 2017년 8월 8일
Hello Alexander,
if you want to display wavelet analysis in terms of frequency one common way is to use the center frequency of the used wavelet.
Using a web search engine you could have searched for "wavelet equivalent frequency" which is providing several useful explanations as: https://de.mathworks.com/videos/understanding-wavelets-part-1-what-are-wavelets-121279.html
Kind regards,
Robert
  댓글 수: 1
Alexander Voznesensky
Alexander Voznesensky 2017년 8월 8일
편집: Alexander Voznesensky 2017년 8월 8일
Thank you. I tried:
[freq,xval,recfreq] = centfrq(wname, N, 'plot');
And I know the points number:
N=length(xval);
But what about Fs? How to define f vector?

댓글을 달려면 로그인하십시오.


Robert U
Robert U 2017년 8월 9일
Hi Alexander,
if you want to plot the Fourier spectrum of the wavelet you can apply the usual fft algorithm (described here: https://de.mathworks.com/help/matlab/math/basic-spectral-analysis.html ).
%%Create wavelet
wname='db20';
N=12;
[phi, psi, tgrid] = wavefun (wname, N);
%%Calculate FFT of wavelet output
SampleFrq = 2^N; % calculate sample frequency of signals
SigL = length(psi); % phi & psi have same length
NFFT = 2^nextpow2(SigL); % standard fft calculation
SigMagPsi = fft(psi,NFFT)/SigL;
SigMagPsi = 2*abs(SigMagPsi(1:NFFT/2+1));
SigMagPhi = fft(phi,NFFT)/SigL;
SigMagPhi = 2*abs(SigMagPhi(1:NFFT/2+1));
f = SampleFrq / 2 * linspace(0,1,NFFT/2+1);
%%Plot Figure
figure;
hold on
plot(f,SigMagPhi);
plot(f,SigMagPsi);
ah = gca;
ah.XScale = 'log';
ah.YLabel.String = 'Magnitude';
ah.XLabel.String = 'Frequency [Hz]';
legend(['Phi';'Psi'])
figure;
centfrq(wname,N,'plot')
  댓글 수: 2
Alexander Voznesensky
Alexander Voznesensky 2017년 8월 9일
편집: Alexander Voznesensky 2017년 8월 9일
Thank you very much! But, the main question is still here: why
SampleFrq = 2^N?
I have some stuff about it:
Fs=10^3; % частота дискретизации, Гц
T=1/Fs; % период дискретизации, сек
N=1e4; % количество отсчетов
t=(0:N-1)*T; % массив отсчетов времени
f=0:Fs/(N-1):Fs; % массив частот
f1=10;
f2=25;
f3=50;
f4=100;
x1=cos(2*pi*f1.*t)+cos(2*pi*f2.*t)+cos(2*pi*f3.*t)+cos(2*pi*f4.*t); % стационарный сигнал
figure;
subplot(2,1,1);
plot(t,x1);
xlabel('t, сек');
ylabel('x');
title('Стационарный сигнал. Временная область');
grid;
subplot(2,1,2);
plot(f,abs(fft(x1)));
xlabel('f, Гц');
ylabel('X');
title('Стационарный сигнал. Частотная область');
grid;
x2_1=cos(2*pi*f4.*t(1:N/4));
x2_2=cos(2*pi*f3.*t(N/4+1:N/2));
x2_3=cos(2*pi*f2.*t(N/2+1:3*N/4));
x2_4=cos(2*pi*f1.*t(3*N/4+1:end));
x2=[x2_1 x2_2 x2_3 x2_4]; % нестационарный сигнал
figure;
subplot(2,1,1);
plot(t,x2);
xlabel('t, сек');
ylabel('x');
title('Нестационарный сигнал. Временная область');
grid;
subplot(2,1,2);
plot(f,abs(fft(x2)));
xlabel('f, Гц');
ylabel('X');
title('Нестационарный сигнал. Частотная область');
grid;
So my Fs is 1000 Hz. What in this case? Is Fs the same for the Fourier spectrum of the wavelet? So:
f=0:Fs/(length(psi)-1):Fs;
Robert U
Robert U 2017년 8월 10일
Hello Alexander:
The basic idea is to understand the generated wavelet as a time-dependent signal that is sampled with a certain (fixed) sampling frequency even though it could be a function depending on any physical (scalar) value (e.g. distance).
Sampling frequency is the step size of your points grid XVAL (tgrid). Assuming that they are equidistantly distributed you can check the equivalent sampling frequency by
Fs = 1 / mean( diff( tgrid ));
You will see that the sampling frequency increases with the number of iterations. You can calculate your sampling frequency either with the formula above or you convince yourself that the scaling is according to
Fs = 2^N;
This feature was documented on earlier versions ( http://radio.feld.cvut.cz/matlab/toolbox/wavelet/wavefun.html ) and is still for wavefun2 ( https://de.mathworks.com/help/wavelet/ref/wavefun2.html).
[PHI,PSI,XVAL] = wavefun('wname',ITER) returns the scaling and wavelet functions on the 2^ITER points grid XVAL.
Kind regards,
Robert

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Wavelet Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by