Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. [data] = loadQucsDataSet("fft_test.dat")
  2. showQucsDataSet(data)
  3. [Vout] = getQucsVariable(data,"out.Vt");
  4. [time] = getQucsVariable(data,"time");
  5. Ts = time(2) - time(1);
  6. fs = 1/Ts;
  7. N = length(Vout);%Ensure that N >> fs/2.
  8. y_fft = fft(Vout, N);%fft returns a vector pi rad shifted. Since we're dealing with real signals, the spectrum is symmetric around f=0. Let's cut the first half...
  9. y_fft = y_fft(1 : round(N/2));%Just cut the first half. No fftshift is needed.
  10. y_fft = 2*y_fft/N;%Now the result must be normalized wrt the number of points. OTOH, since we've just removed the second half of the spectrum, we must multiply the result by 2.
  11. freq = linspace(0, fs/2, N/2);%Prepare the freq axis...
  12. clf();
  13. y_abs = abs(y_fft);
  14.  
  15. %Check the result is correct
  16. [max_val, posx] = max(y_abs);
  17. max_val
  18. f_tone = freq(posx);
  19. f_tone
  20.  
  21. %Plot the result
  22. span = 3e3;%3kHz
  23. fc = 1e3;
  24. plot(freq, y_abs)
  25. title("Single-sided spectrum");
  26. xlabel("Frequency (Hz)");
  27. ylabel("Amplitude (V)");
  28. grid on
  29. axis ([fc-span/2 fc+span/2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement