Zero Pad My FFT Signal and Window

51 vues (au cours des 30 derniers jours)
David Harra
David Harra le 4 Avr 2022
Hi Everyone I want to know how I can zero pad my FFT signal to make it longer so that I can get better frequency resolution. In my line of code below that shows (FTSignal = fft(Signal-meanSignal, 15000000)/N), I thought this number would define the zero padding, but I am not confident it is doing what I believe it to do.
I have also applied my hanning window in my FFT domain, I have been told it is better to do this in the time domain before FFT, but based on my code below I am not too sure what to do. I did try Data=hann(length(Data)) but this is incorrect.
Any pointers for the zero padding and windowing would be appreciated
%% Read in Data
FName = 'Tit_10MHz_110F.flxhst';
MyData = read_history(FName);
Time = MyData.TimeRecB.Time;
Data= MyData.DataRecB(1).Data;
%% Take the signal and normalize
Data = Data./max(abs(Data)); % This is the normalized signal
% Data=hann(length(Data))
%% Plot the time domain signal
figure(1)
plot(Time*1e6, Data);
grid
xlabel('Time \mus')
ylabel('Amplitude')
%% Set up the FFT Parameteres
Signal= Data;
Ts=Time(2)- Time(1); %Time Step
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz) half of the sampling rate of a discrete signal processing system
N = length(Signal); % Lengh of signal
meanSignal = mean(Signal); % ‘Signal’ Mean
FTSignal = fft(Signal-meanSignal, 15000000)/N; % Normalised Fourier Transform Of Baseline-Corrected &Signale& zero Padded
FTSignal = fft((Signal(:)-meanSignal) .* hann(length(Signal)) ) / N; %Apply hanning window to the data
%% Set up FFT Verctors
Fv = linspace(0, 1, fix(numel(FTSignal)/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
%% Plot FFT
figure(2)
plot(Fv/1e6, abs(FTSignal(Iv))*2)
xlim([0 20])
grid
xlabel('Frequency(MHz)')
ylabel('Amplitude')

Réponse acceptée

Star Strider
Star Strider le 4 Avr 2022
Modifié(e) : Star Strider le 4 Avr 2022
I recognise my code!
I see nothing wrong with that (although I do not understand the two fft calls), however I would change it to:
NFFT = 2^nextpow2(15000000);
FTSignal = fft(Signal-meanSignal, NFFT)/N; % Normalised Fourier Transform Of Baseline-Corrected &Signale& zero Padded
for efficiency.
The ‘Fv’ assignment is correct. (It is taken from the R2015b documentation.)
Similarly, this would likely work:
FTSignal = fft((Signal(:)-meanSignal, NFFT) .* hann(length(Signal)) ) / N; %Apply hanning window to the data
although it wouold be necessary to experiment with it in the event that:
hann(NFFT)
produces a better result.
EDIT —
I cannot import the data:
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/952214/Matlab.zip')
Uz = 1×3 cell array
{'Matlab/New_FFT.m'} {'Matlab/read_history.m'} {'Matlab/Tit_10MHz_110F.flxhst'}
T1 = readtable(Uz{3})
Error using readtable
'.flxhst' is not a recognized file extension. Unable to detect file type. To read the file as a specific file type, regardless of file extension, use the 'FileType' name-value pair.
.

Plus de réponses (1)

Matt J
Matt J le 4 Avr 2022
Modifié(e) : Matt J le 4 Avr 2022
The zero-padding is fine. The way you set up your frequency axis, I'm a little unsure about.
N=numel(FTSignal);
NormalizedAxis= (0:N-1)-ceil((N-1)/2);
Fv=NormalizedAxis/N/Ts;
plot(Fv,fftshift(abs(FTSignal)))
  4 commentaires
David Harra
David Harra le 4 Avr 2022
Hi Matt, I have attached my data and files which should just run for you no problem. Really appreciated if you could have a look at this.
Matt J
Matt J le 4 Avr 2022
Could you just attach a .mat file containing Data. That's all we need to run your code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by