# fft tool - amplitude dependence vs. frequency

10 views (last 30 days)
David Lopez on 22 Sep 2021
Commented: David Lopez on 23 Sep 2021
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 CommentsShowHide 1 older comment
David Lopez on 23 Sep 2021
for example F1 = 10 Hz -> Power = 10 dBm as expected for F1 = 270 Hz power = 8.9 dBm... thks

Paul on 23 Sep 2021
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
David Lopez on 23 Sep 2021
works perfectly
thanks a lot

R2021a

### Community Treasure Hunt

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

Start Hunting!