Permutation test in EEG data

I have a question about permutation test.If I have AB two conditions, EEG data is trialXtimeXfreq, I need to first replace trial based on each subject, get the distribution of each subject, form permXtrialXtimeXfreq. each subject so, and then finally based on the subject dimension to permute. Or can you tell us the steps to get a permutaion ttest? Thank you