Zero Pad My FFT Signal and Window
20 views (last 30 days)
Show older comments
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')
0 Comments
Accepted Answer
Star Strider
on 4 Apr 2022
Edited: Star Strider
on 4 Apr 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')
T1 = readtable(Uz{3})
.
0 Comments
More Answers (1)
Matt J
on 4 Apr 2022
Edited: Matt J
on 4 Apr 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 Comments
Matt J
on 4 Apr 2022
Could you just attach a .mat file containing Data. That's all we need to run your code.
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!