MATLAB Answers

fft tool - amplitude dependence vs. frequency

조회 수: 10(최근 30일)
David Lopez
David Lopez 2021년 9월 22일
댓글: David Lopez 2021년 9월 23일 11:05
Hi,
I am trying to test a signal in the frequency domain. For the test I have tried a continuous wave, a sinus. I have noticed that the spectral amplitude of my signal change in function of its frequency (F1 in my example).
I have my Pin1_dBm only for F1 very low...
is it linked to the time windowing too long that we see a sort of sincardinal in the frequency domain?
thanks
here is the script :
%declarations
Fs = 1e3; %sample frequency
F1=0.42e3; %signal frequency
Tstop=2.54e6/Fs; %time window - duration of my simulation
t = 0:1/Fs:Tstop; %time step
Pin1_dBm=10; %power level of my signal
nbre_step=Tstop*Fs; %number of time steps during my time window
x = sqrt(2*10^((Pin1_dBm-30)/10))*cos(2*pi*F1*t); % my signal (Continuous wave)
In_spectrum_2sided_W=(abs(fft(x))/nbre_step).^2; %spectrum 2 sided in Watts
In_spectrum_1sided_W=In_spectrum_2sided_W(1:nbre_step/2+1);
In_spectrum_1sided_W(2:end-1)=2*In_spectrum_1sided_W(2:end-1); %spectrum 2 sided->1sided in Watts
In_spectrum_dBm=10*log10(1000*In_spectrum_1sided_W); %spectrum in dBm
freq=Fs*(0:(nbre_step/2))/nbre_step;
plot(freq,In_spectrum_dBm);
  댓글 수: 2
David Lopez
David Lopez 2021년 9월 23일 10:45
for example F1 = 10 Hz -> Power = 10 dBm as expected
for F1 = 270 Hz power = 8.9 dBm...
thks

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

채택된 답변

Paul
Paul 2021년 9월 23일 0:05
For pure sinusoidal signals, the "expected" result is only obtained when the length, N, of the FFT satisfies
N = M*Fs/F1
where M is an integer, Fs, is the sampling frequency, and F1 is the frequency of the sinusoid, and of course we need Fs/F > 2. The code in the question doesn't quite satisify this requirement for either F1 = 10 Hz or F1 = 270 Hz. To illustrate
Fs = 1e3; % sample frequency
F1 = [10 270]; % signal frequency
Tstop = 2.54e6/Fs; % duration
t = 0:1/Fs:Tstop; % time step
N = numel(t) % number of samples in the FFT
N = 2540001
M = N.*F1./Fs
M = 1×2
1.0e+05 * 0.2540 6.8580
M == round(M) % check for integer value
ans = 1×2 logical array
0 0
So we see that M is not integer for the selected parameters. Modify the defnition of t by just one sample
t = (0:2.54e6-1)/Fs;
N = numel(t)
N = 2540000
M = N.*F1./Fs
M = 1×2
25400 685800
M == round(M) % check for integer value
ans = 1×2 logical array
1 1
Now let's make the plots for the selected values of F1
figure;
temp(Tstop,Fs,F1(1),t); % use a function to avoid having to rewrite code
hold on;
plot(F1(1),10,'o'),grid
figure;
temp(Tstop,Fs,F1(2),t); % use a function to avoid having to rewrite code
hold on;
plot(F1(2),10,'o'),grid
Now both cases yield the expected result. In these cases, the FFT at frequencies not equal to F1 should be exactly zero. But there will be some numerical noise, as seen in the plots.
Also, consider taking appropriate action if nbre_step is odd.
function temp(Tstop,Fs,F1,t)
Pin1_dBm=10; %power level of my signal
nbre_step=Tstop*Fs; %number of time steps during my time window
x = sqrt(2*10^((Pin1_dBm-30)/10))*cos(2*pi*F1*t); % my signal (Continuous wave)
In_spectrum_2sided_W=(abs(fft(x))/nbre_step).^2; %spectrum 2 sided in Watts
In_spectrum_1sided_W=In_spectrum_2sided_W(1:nbre_step/2+1);
In_spectrum_1sided_W(2:end-1)=2*In_spectrum_1sided_W(2:end-1); %spectrum 2 sided->1sided in Watts
In_spectrum_dBm=10*log10(1000*In_spectrum_1sided_W); %spectrum in dBm
freq=Fs*(0:(nbre_step/2))/nbre_step;
plot(freq,In_spectrum_dBm);
end
  댓글 수: 1
David Lopez
David Lopez 2021년 9월 23일 11:05
works perfectly
thanks a lot

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

추가 답변(0개)

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by