10 views (last 30 days)

Show older comments

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);

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

M = N.*F1./Fs

M == round(M) % check for integer value

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)

M = N.*F1./Fs

M == round(M) % check for integer value

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

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

Start Hunting!