Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

fft working but end time of waveform distorting result

1 visualización (últimos 30 días)
Nathan Kennedy
Nathan Kennedy el 13 de Dic. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi, I am having a problem that my amplitudes are being affected when I change the end time that my waveform is sampled for.
My code is below. If I changed my end time (end_t) then it all goes wrong and my amplitudes are messed up and it doesn't capture every frequency and correct amplitude in the waveform. I am basically extending the end_t so I can capture more of the waveform in the time domain -> this isn't plotted below, only the frequency domain after fft.
Also I am unsure if I should be using L or L2 in the code. It works as is, but if I use L2 it doesn't and if I extend end_t then it goes rapidly down hill. Please can someone advise
%Setup sampling and frequency range
f=( 20.2 : 0.01 : 21.2)*10^9 %frequency range
Fs = 4*max(f) ; %Sample at least 2x max frequency to prevent nyquist folding
Ts = 1/Fs; %sample time
end_t = 10^-7 ; % === EVERYTHING GOES WRONG IF CHANGED ====
dt = 0: Ts : end_t-Ts; %signal duration
%Make evenly spaced cosines within the frequency range
for a = 1:length(f)-1
y(a,:) = 2 * cos (2*pi .*f(a) .* dt);
end
waveform = sum(y); % Make the summed waveform
%Setup fft
L = length(waveform); %length of time domain signal for fft
% L2 = 2^nextpow2(L); %Not sure if I should be using L2 instead of L in below code
f_domain = Fs*(0:L/2-1)/L; %Convert fft samples to frequency
ft = fft(waveform,L);
ft_real = abs(ft);
ft_real_half = ft_real(1:L/2);
ft_normalised = (ft_real_half / L )*2 % Every fft requires 2*?
bar(f_domain,ft_normalised)
xlabel('Frequency (GHz)');
ylabel('Actual Amplitude');
xlim([19.2*10^9 22.2*10^9]);
ylim([0 2*max(ft_normalised)]);
This should give you a square block in frequency domain, my carrier waveform. But it distorts when end_t is extended so it samples for longer. Please can someone advise

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by