User Tools

Site Tools


ptm_basic

Adapted Wavelets used to perform pattern detection in PTM produced signal of instantaneous frequency fluctuation


Four pattern wavelets are currently available. F1 - taken from the original shoaling breaker (not shown), F2, F3 and F4 with linear rise and then exponential decay (see Figure below: black, red, magenta).
The files are included.

Version 2

This version was prepared to process the data before WISE2018. The files are here, folder V2. The code is somewhat “messi” and contains several scripts written to process different types of data, namely
1. Linear focusing breaking waves.
wave_analysis_NoVideo_ONEWG.m

2. Mechanical swell + wind
wave_analysis_NoVideo_ONEWG.m and CountBreakersWWandMW_v1.mat

3. Wind generated waves at several fetches
CountBreakersperFetch.m

Some codes will load the video and some not. Read the code.

Version 3

Clean version created on May 3rd, 2018. All routines were rewritten into several dedicated functions, all are documented inside the functions. The functions were written to treat one signal at a time. Looping on numerous files or wave gauges has to be performed outside the functions.
The functions are:
1. FreqVarHilbertClean.m - Calculates the F(t) from eta.
2. LowPass.m - Low Pass filtering.
3. SigCondit.m - Signal (F(t)) conditioning/enhancement, such as amplification, zeroing at times of negative eta, lowpass filtering.
4. VideoFramesColl.m - Identifying video frames and numbering in sync with time vector.
5. ZeroCross.m - Detecting zero crossings in eta, for detection of crests.
6. PatternRecWavelet.m - Loads pattern wavelet and performs adapted wavelet transform. The result is relative energy, higher with waves resembling the pattern.
7. DetectBreaksLoc.m - Works with wavelet transform results from 6. and counts the breakers detected, also returns % of breakers detected and their times.


An example code processing one WG file from a selected file with or without accompanying video is named Example_Detect_One_File.m, the code is also given below.

%% Example breaking detection on one WG record with video
% V3 version

%% Clean
clear all; close all; clc;

%% Basic settings:
Fs=1600;        % sampling frequency
FN='F1.mat';    % Wavelet to use, by name
DetPRCT=0.7;    % % of max energy threshold for detection
WGc=1;          % Collumn number of WG data
Vc=6;           % column number of video sync data, 0 if no video
Fc=0;          % Low Pass cutoff frequency, 0 if not needed
Noct=64;        % N. of octaves for wavelets (resolution)

%% Load files, filenames etc.:
[Filedat,pathdat] = uigetfile('*.dat','Select the data file file');
data=load([pathdat, Filedat]); [n,m]=size(data); if m>n; data=data'; end;
eta=data(:,WGc)-mean(data(:,WGc));
if Vc
    Vsync=data(:,Vc);
    [vid_file,path] = uigetfile('*.avi','Select the video file',pathdat);
end

%% Pefrom basic calculations:
% Obtain F(s) by Hilbert transform:
[t,frr]=FreqVarHilbertClean(eta, Fs);
% Condition the signal (filter amplification crests detection)
[fr, tmax, maxe]=SigCondit(eta, frr, Fs, Fc);
% Video file frames count if Vc is given non zero
if Vc
    [time_frame_break]=VideoFramesColl(eta, Fs, path, vid_file, tmax, Vsync);
end


%% Plots:
if Vc; pn=3; else; pn=2; end;
figure(1);

a1=subplot(pn,1,1);% plot eta and peaks
plot(t,eta,'-b'); grid on;
hold on; scatter(tmax,maxe,20,'ro','filled');
xlabel('t[sec]');ylabel('eta[mm]');
legend('eta','crests');

a2=subplot(pn,1,2);% plot frequency and filtered frequency
plot(t,frr,'k');hold on;plot(t,fr,'r'); grid on
% ylim([-100 100]);
xlabel('t[sec]');ylabel('f(t)[rad/sec]');
legend('fr-without low pass filter','fr-low pass filter and amp');
hold off;

if Vc
    a3=subplot(pn,1,3);% plot frequncy
    plot(t,frr,'k');hold on;plot(t,fr,'r'); grid on
    a3.XTick=(time_frame_break(:,1)); a3.XTickLabel=({time_frame_break(:,2)});
    xlabel('frame[#]');ylabel('f(t)[rad/sec]');
    legend('fr-without low pass filter','fr-low pass filter and amp');
    hold off;
    linkaxes([a1,a2,a3],'x');
else
    linkaxes([a1,a2],'x');
end

%% Now Wavelets to detect the patterns:
% Wavelets:
[C, fsc]=PatternRecWavelet(fr, Fs, FN, Noct);
% Detect
[Ndet, Ndetprct, Is, Cc]=DetectBreaksLoc(C, DetPRCT, Fs, tmax);

%% Plot again, this time detected breakers positions, coefs maps, etc.
figure(2)

a21=subplot(3,1,1);% plot eta and peaks
plot(t,eta,'-b'); grid on;
hold on; scatter(tmax,maxe,20,'ro','filled');
plot(t(round(Is)),zeros(length(Is),1),'kx','MarkerSize',10,'LineWidth',1);
xlabel('t[sec]');ylabel('eta[mm]');
legend('eta','crests', 'breakers');

a22=subplot(3,1,2);% plot frequency and filtered frequency
plot(t,fr,'k'); grid on
if Vc
    a22.XTick=(time_frame_break(:,1)); a22.XTickLabel=({time_frame_break(:,2)});
    xlabel('frame[#]');ylabel('f(t)[rad/sec]');
else
    xlabel('t[sec]');ylabel('f(t)[rad/sec]');
end
legend('fr-low pass filter and amp');
hold off;

a23=subplot(3,1,3);% plot frequncy
imagesc(t,fsc,abs(C)); colorbar;

linkaxes([a21,a22,a23],'x');

Version 4

Small but significant change from Version 3: addition of low pass filtering the Wavelets analysis results down to twice fp, fp being the waves dominant frequency.
LowPass2D.m - low pass filter the wavelets coefficients matrix. Cuttoff frequency of 2xfp gives good results.
The files are here
Example usage code is below:

%% Example breaking detection on one WG record with video
% V4 version

%% Clean
clear all; close all; clc;

%% Basic settings:
Fs=1600;        % sampling frequency
FN='F3.mat';    % Wavelet to use, by name
DetPRCT=0.8;    % % of max energy threshold for detection
WGc=1;          % Collumn number of WG data
Vc=0;           % column number of video sync data, 0 if no video
Fc=30;          % Low Pass cutoff frequency, 0 if not needed
fc=5;           % Low Pass cutoff frequency for Coeffs 
Noct=64;        % N. of octaves for wavelets (resolution)

%% Load files, filenames etc.:
[Filedat,pathdat] = uigetfile('*.dat','Select the data file file');
data=load([pathdat, Filedat]); [n,m]=size(data); if m>n; data=data'; end;
eta=data(:,WGc)-mean(data(:,WGc));
if Vc
    Vsync=data(:,Vc);
    [vid_file,path] = uigetfile('*.avi','Select the video file',pathdat);
end
clear data;
%% Pefrom basic calculations:
% Obtain F(s) by Hilbert transform:
[t,frr]=FreqVarHilbertClean(eta, Fs);
% Condition the signal (filter amplification crests detection)
[fr, tmax, maxe]=SigCondit(eta, frr, Fs, Fc);
% Video file frames count if Vc is given non zero
if Vc
    [time_frame_break]=VideoFramesColl(eta, Fs, path, vid_file, tmax, Vsync);
end


%% Plots:
if Vc; pn=3; else; pn=2; end;
figure(1);

a1=subplot(pn,1,1);% plot eta and peaks
plot(t,eta,'-b'); grid on;
hold on; scatter(tmax,maxe,20,'ro','filled');
xlabel('t[sec]');ylabel('eta[mm]');
legend('eta','crests');

a2=subplot(pn,1,2);% plot frequency and filtered frequency
plot(t,frr,'k');hold on;plot(t,fr,'r'); grid on
% ylim([-100 100]);
xlabel('t[sec]');ylabel('f(t)[rad/sec]');
legend('fr-without low pass filter','fr-low pass filter and amp');
hold off;

if Vc
    a3=subplot(pn,1,3);% plot frequncy
    plot(t,frr,'k');hold on;plot(t,fr,'r'); grid on
    a3.XTick=(time_frame_break(:,1)); a3.XTickLabel=({time_frame_break(:,2)});
    xlabel('frame[#]');ylabel('f(t)[rad/sec]');
    legend('fr-without low pass filter','fr-low pass filter and amp');
    hold off;
    linkaxes([a1,a2,a3],'x');
else
    linkaxes([a1,a2],'x');
end

%% Now Wavelets to detect the patterns:
% Wavelets:
[C, fsc]=PatternRecWavelet(fr, Fs, FN, Noct);
% Low pass Filter C
Csl=LowPass2D(C,Fs,fc);
% Detect
[Ndet, Ndetprct, Is, Cc]=DetectBreaksLoc(Csl, DetPRCT, Fs, tmax);

%% Plot again, this time detected breakers positions, coefs maps, etc.
figure(2)

a21=subplot(3,1,1);% plot eta and peaks
plot(t,eta,'-b'); grid on;
hold on; scatter(tmax,maxe,20,'ro','filled');
plot(t(round(Is)),zeros(length(Is),1),'kx','MarkerSize',10,'LineWidth',1);
xlabel('t[sec]');ylabel('eta[mm]');
legend('eta','crests', 'breakers');

a22=subplot(3,1,2);% plot frequency and filtered frequency
plot(t,fr,'k'); grid on
if Vc
    a22.XTick=(time_frame_break(:,1)); a22.XTickLabel=({time_frame_break(:,2)});
    xlabel('frame[#]');ylabel('f(t)[rad/sec]');
else
    xlabel('t[sec]');ylabel('f(t)[rad/sec]');
end
legend('fr-low pass filter and amp');
hold off;

a23=subplot(3,1,3);% plot frequncy
imagesc(t,fsc,Csl); 

linkaxes([a21,a22,a23],'x');

Example result, linear focusing breaking.

ptm_basic.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki