Zero Pad My FFT Signal and Window

51 次查看(过去 30 天)
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')

采纳的回答

Star Strider
Star Strider 2022-4-4
编辑:Star Strider 2022-4-4
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.
.

更多回答(1 个)

Matt J
Matt J 2022-4-4
编辑:Matt J 2022-4-4
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 个评论
David Harra
David Harra 2022-4-4
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 2022-4-4
Could you just attach a .mat file containing Data. That's all we need to run your code.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by