How do i scale to my axis after fft?

조회 수: 19 (최근 30일)
Cherie Lim
Cherie Lim 2020년 1월 20일
댓글: Cherie Lim 2020년 1월 21일
My spectrum is of the correct shape, however i am having difficulty in scaling correctly to the frequency domain for the correct frequency bins after fft.
I have comment out the lines of my codes that may require addition of insights and knowledge.
clear all;
close all;
clc;
%% Basic Parameters
w = 0.1; %defined as P_0*tau_0/E_sat or E_in
Fs = 100; %Sampling frequency
tau = -3:1/Fs:3; %0.01 = 1/Fs
alpha = 5;
hold on
%% First iteration
G_0 = 1;
x = (1/2)*sqrt(pi)*w*(1 + erf(tau)); %x = U_in(tau)! %error function!
h = -log(1-(1-(1/G_0))*exp(-x)); %h!
G = G_0./(G_0 -(G_0-1)*exp(-x)); %G!
y = exp(-tau.^2).*G; %y = P_in !
y_out = y.*G; %y = P_out!
phi_out = 0.5*alpha.*h; %phi_out (without phase input)!
% h_dot = -y.*(G-1); %h_dot!
signal = ((y.^0.5).*exp(0.5.*h - (1i .* phi_out)));
% nfft = length(signal); %length of time domain signal
% nfft2 = 2^nextpow2(nfft); %length of signal in power of 2 Need help here!
%need help here!
spectrum = fft(signal);
spectrum = fftshift(spectrum);
spectrum = abs(spectrum).^2;
spectrum_max = max(spectrum);
figure(1);
plot(tau,spectrum/spectrum_max,'g--','LineWidth',0.5);
hold on
%% Subsequent Iterations
for G_0 = [10 100 1000]
x = (1/2)*sqrt(pi)*w*(1 + erf(tau)); %x = U_in(tau)! %error function!
h = -log(1-(1-(1/G_0))*exp(-x)); %h!
G = G_0./(G_0 -(G_0-1)*exp(-x)); %G!
y = exp(-tau.^2).*G; %y = P_in !
y_out = y.*G; %y = P_out!
phi_out = 0.5*alpha.*h; %phi_out (without phase input)! how to obtain phaseinput?
% h_dot = -y.*(G-1); %h_dot!
signal = ((y.^0.5).*exp(0.5.*h - (1i .* phi_out)));
spectrum = fft(signal);
spectrum = fftshift(spectrum);
spectrum = abs(spectrum).^2;
spectrum_max = max(spectrum);
figure(1);
plot(tau,spectrum/spectrum_max,'LineWidth',1);
end
%% Plot-labels
xlabel('(v-v_0)tau','FontSize',14);
ylabel('Normalized power','FontSize',14);
set(gca,'FontSize',14); % size of tick marks on both axes
legend('G_0= Input','G_0= 10 dB','G_0= 20 dB','G_0= 30 dB');
grid on

채택된 답변

David Goodmanson
David Goodmanson 2020년 1월 21일
Hi Cherie,
you have a time array of length, 601 and spacing deltat = .01. The frequency array is going to be 601 points with to-be-determined spacing deltaf. For an N-point fft the basic golden rule for time and frequency array spacing is
deltat*deltaf= 1/N
Equivalently, most people would look at this as
deltat = 1/Fs deltaf = Fs/N
Either way, you can find deltaf. If you use fft shift as you are doing, for an odd number of points the frequency array is
f = (-(N-1)/2:(N-1)/2)*deltaf = (-(N-1)/2:(N-1)/2)*Fs/N
and for an even number of points it would be
f = (-N/2:N/2-1)*deltaf = (-N/2:N/2-1)*Fs/N
It looks like you have nextpow2 in your code, although you are not using it. I would STRONGLY advise against using nextpow2. It can cause a lot of problems to change N (I have seen this many times on this website), and unless you have some crazy large number of points, in my opinion the supposed benefit you get, if any, is stupidly minuscule.
  댓글 수: 3
David Goodmanson
David Goodmanson 2020년 1월 21일
Hi Cherie,
if you mean that most of the action is near f=0 and the data is small as you get away from f=0, that's common. Getting rid of the data won't be good if you ever want to ifft back to the time domain. For plotting purposes you could just use xlim([-f0 f0]) after the plot command, for a suitably chosen f0.
Cherie Lim
Cherie Lim 2020년 1월 21일
thank you so much! you have been a great help in my progress!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by