MATLAB: Fourier analysis of waveforms and clipping wave, HELP PLEASE!!!

clippingfftfilterinitial peakMATLABspectrumtaperwaveform

Hello all, (Below I have included sample data) So I am working on the fourier spectrum of a waveform. However I need to only take the initial peak of the waveform (the 1 to 1.5 period) of the waveform that I have and achieve a fourier spectrum for that. This has proved to be quite difficult as truncating the waveform is no good as it adds high frequencies to the spectrum. I am clipping the waveform with a find() index command and simply adding a few index values before and after the clip and worked to taper the waveform off using a hamming window (also tried blackman window). There must be a better way of doing this, perhaps building a filter, however I am unsure how to do this. Or perhaps I am doing something else wrong in my calculations. (Sorry for the big question, Been teaching myself matlab for a few months now have been stumped for a while on this problem.)
My code is as follows:
alumdt=1E-8; % Time Step
alumt0=0+alumdt; % Start pick point
alumFs=1/alumdt; % Sampling Frequency
L=9999; % Length
alumt=(0:L-1)*alumdt; % Time array by steps of dt
alumAmplP=alumdata (9:10008,5); % Amplitude Array P wave
NFFT=2^nextpow2(L); % Nyquist Frequecy maybe, length of Fourier window

alumfP=alumFs/2*linspace (0,1,NFFT/2+1);
alumAmplP_2=alumAmplP (1:L); % Amplitude through all steps

alumYP=fft (alumAmplP_2,NFFT)/L;
absalumYP=abs(alumYP);
AlumSpectrum = [transpose(alumfP),2*absalumYP(1:NFFT/2+1)];
absoluteRange = (0:1500:1.25*10^8);
alumYYP = interp1(transpose(AlumSpectrum(1:8193,1)),AlumSpectrum(1:8193,2),absoluteRange);
alumPick = find(alumAmplP > .025, 1, 'first') - 200;
alumPickEnd = alumPick + 600;
alumTimePick = (alumPick*alumdt:alumdt:alumPickEnd*alumdt);
ClippedAlumWave = alumAmplP(alumPick:alumPickEnd);
ClippedAlumT = (alumTimePick);
TaperClippedAlumWave = window(@hamming,numel(ClippedAlumT)).*transpose(ClippedAlumWave)';
%L2 = 319;
alumL2 = length(alumTimePick);
NFFT=2^nextpow2(L); % Nyquist Frequecy maybe, length of Fourier window
alumfP=alumFs/2*linspace (0,1,NFFT/2+1);
ClippedalumAmplP_2=TaperClippedAlumWave; % Amplitude through all steps
ClippedalumYP=fft (ClippedalumAmplP_2,NFFT)/alumL2;
absClippedalumYP = abs(ClippedalumYP);
ClippedAlumSpectrum = [transpose(alumfP),2*absClippedalumYP(1:NFFT/2+1)];
absoluteRange = (0:1500:1.25*10^8);
ClippedalumYYP = interp1(transpose(ClippedAlumSpectrum(1:8193,1)),ClippedAlumSpectrum(1:8193,2),absoluteRange);
figure(1)
subplot(2,1,1)
hold on
plot(alumt, alumAmplP(1:9999))
title('Aluminum Wave-Form')
xlabel('Time (s)')
ylabel('Amplitude')
hold on
line([alumPick*alumdt alumPick*alumdt], [-.15 .15])
line([alumPickEnd*alumdt alumPickEnd*alumdt], [-.15 .15])
subplot(2,1,2)
hold on
plot(absoluteRange,alumYYP)
title('Aluminum Spectrum')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlim([0 1.5E6])
figure(2)
subplot(2,1,1)
hold on
plot(ClippedAlumT,TaperClippedAlumWave)
title('Aluminum Wave-Form Initial Peak')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(2,1,2)
hold on
plot(absoluteRange, ClippedalumYYP)
title('(Clip) Aluminum Spectrum')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlim([0 1.5E6])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Please help if you can, Thank you so much, Dan
Below I have posted some sample data. the time step for the sample data is 1E-8 = dt

<pre class="language-matlab">-0.0090
-0.0095
-0.0091
-0.0097
-0.0106
-0.0121
-0.0131
-0.0141
-0.0142
-0.0159
-0.0172
-0.0187
-0.0188
-0.0206
-0.0225
-0.0237
-0.0249
-0.0257
-0.0278
-0.0299
-0.0310
-0.0327
-0.0355
-0.0367
-0.0388
-0.0392
-0.0430
-0.0445
-0.0464
-0.0476
-0.0504
-0.0526
-0.0547
-0.0579
-0.0583
-0.0597
-0.0616
-0.0636
-0.0655
-0.0670
-0.0710
-0.0705
-0.0730
-0.0741
-0.0749
-0.0766
-0.0788
-0.0787
-0.0796
-0.0811
-0.0803
-0.0818
-0.0811
-0.0800
-0.0804
-0.0805
-0.0782
-0.0778
-0.0772
-0.0748
-0.0735
-0.0716
-0.0685
-0.0670
-0.0638
-0.0607
-0.0571
-0.0545
-0.0507
-0.0454
-0.0409
-0.0366
-0.0315
-0.0272
-0.0220
-0.0162
-0.0108
-0.0044
0.0015
0.0069
0.0141
0.0219
0.0302
0.0360
0.0425
0.0490
0.0571
0.0655
0.0721
0.0795
0.0866
-0.0024
-0.0040
-0.0039
-0.0042
-0.0047
-0.0054
-0.0052
-0.0072
-0.0071
-0.0090
-0.0095
-0.0091
-0.0097
-0.0106
-0.0121
-0.0131
-0.0141
-0.0142
-0.0159
-0.0172
-0.0187
-0.0188
-0.0206
-0.0225
-0.0237
-0.0249
-0.0257
-0.0278
-0.0299
-0.0310
-0.0327
-0.0355
-0.0367
-0.0388
-0.0392
-0.0430
-0.0445
-0.0464
-0.0476
-0.0504
-0.0526
-0.0547
-0.0579
-0.0583
-0.0597
-0.0616
-0.0636
-0.0655
-0.0670
-0.0710
-0.0705
-0.0730
-0.0741
-0.0749
-0.0766
-0.0788
-0.0787
-0.0796
-0.0811
-0.0803
-0.0818
-0.0811
-0.0800
-0.0804
-0.0805
-0.0782
-0.0778
-0.0772
-0.0748
-0.0735
-0.0716
-0.0685
-0.0670
-0.0638
-0.0607
-0.0571
-0.0545
-0.0507
-0.0454
-0.0409
-0.0366
-0.0315
-0.0272
-0.0220
-0.0162
-0.0108
-0.0044
0.0015
0.0069
0.0141
0.0219
0.0302
0.0360
0.0425
0.0490
0.0571
0.0655
0.0721
0.0795
0.0866
-0.0024
-0.0040
-0.0039
-0.0042
-0.0047
-0.0054
-0.0052
-0.0072
-0.0071
-0.0090
-0.0095
-0.0091
-0.0097
-0.0106
-0.0121
-0.0131
-0.0141
-0.0142
-0.0159
-0.0172
-0.0187
-0.0188
-0.0206
-0.0225
-0.0237
-0.0249
-0.0257
-0.0278
-0.0299
-0.0310
-0.0327
-0.0355
-0.0367
-0.0388
-0.0392
-0.0430
-0.0445
-0.0464
-0.0476
-0.0504
-0.0526
-0.0547
-0.0579
-0.0583
-0.0597
-0.0616
-0.0636
-0.0655
-0.0670
-0.0710
-0.0705
-0.0730
-0.0741
-0.0749
-0.0766
-0.0788
-0.0787
-0.0796
-0.0811
-0.0803
-0.0818
-0.0811
-0.0800
-0.0804
-0.0805
-0.0782
-0.0778
-0.0772
-0.0748
-0.0735
-0.0716
-0.0685
-0.0670
-0.0638
-0.0607
-0.0571
-0.0545
-0.0507
-0.0454
-0.0409
-0.0366
-0.0315
-0.0272
-0.0220
-0.0162
-0.0108
-0.0044
0.0015
0.0069
0.0141
0.0219
0.0302
0.0360
0.0425
0.0490
0.0571
0.0655
0.0721
0.0795
0.0866
-0.0024
-0.0040
-0.0039
-0.0042
-0.0047
-0.0054
-0.0052
-0.0072
-0.0071
-0.0090
-0.0095
-0.0091
-0.0097
-0.0106
-0.0121
-0.0131
-0.0141
-0.0142
-0.0159
-0.0172
-0.0187
-0.0188
-0.0206
-0.0225
-0.0237
-0.0249
-0.0257
-0.0278
-0.0299
-0.0310
-0.0327
-0.0355
-0.0367
-0.0388
-0.0392
-0.0430
-0.0445
-0.0464
-0.0476
-0.0504
-0.0526
-0.0547
-0.0579
-0.0583
-0.0597
-0.0616
-0.0636
-0.0655
-0.0670
-0.0710
-0.0705
-0.0730
-0.0741
-0.0749
-0.0766
-0.0788
-0.0787
-0.0796
-0.0811
-0.0803
-0.0818
-0.0811
-0.0800
-0.0804
-0.0805
-0.0782
-0.0

Best Answer

I'm not sure how you are using the term "period" here. If you are talking about only the first 1 of the fundamental frequency which is 1 MHz here, then I think you want at least a few periods to do a spectral analysis even with a clean waveform. The resolution in the DFT (implemented by fft) depends on the number of samples. The more samples, the better the resolution.
In your case, it's easy to see that
xnew = x(1:2800);
gives you the initial waveform, so why not use this?
Fs = 1/1e-8;
d = fdesign.lowpass('Fp,Fst,Ap,Ast',1.2e6,1.4e6,0.5,60,Fs);
Hd = design(d,'butter');
xnew = x(1:2800);
y = filter(Hd,detrend(xnew,0));
ydft = fft(y);
freq = 0:Fs/length(y):Fs/2;
ydft = ydft(1:floor(length(y)/2)+1);
% Plot in MHz
plot(freq./1e6,abs(ydft))
axis([0 10 0 max(abs(ydft))+20])
xlabel('MHz'); ylabel('Magnitude');
If you copy and paste the above code, it works fine.