EEG analysis note
  • 前言
  • Preprocessing notes
  • 有用的链接
  • 基线
  • 时间频率分析 基础
  • make waves
  • FFT
  • Matlab FFT ref
  • ERSP
  • FFT vs. Morlet
  • Pad ratio
  • 时频顺序
  • std_ersp还是newtimef
  • eeglab的PLOT
  • eeglab的统计模块
  • 小波
Powered by GitBook
On this page
  • Creating a simple sine wave
  • Creating a complex wave

Was this helpful?

make waves

Previous时间频率分析 基础NextFFT

Last updated 5 years ago

Was this helpful?

Creating a simple sine wave

To create a sine wave, you need four parameters: D = duration of the signal, here specified in seconds S = sampling rate, samples per second F = frequency, in Hz P = phase, as an angle

%-------------------------------------------------------------------------------------
% make_sig.m
%-------------------------------------------------------------------------------------
D = 1; % signal duration, 1 second
S = 1000; % sampling rate, i.e. N points pt sec used to represent sine wave
F = 50; % frequency in Hz
P = 1 % NB. 2 pi radians = 360 degrees
T = 1/S; % sampling period, i.e. for this e.g. points at 1 ms intervals
t = [T:T:D]; % time vector %NB corrected from previous version
myphi=2*pi*P;
mysig = sin(2*F*t*pi+ myphi); % sinusoidal signal; 2*F*t*pi is freq in radians
figure; plot(t,mysig);
ylim([-2,2])
xlim([0,2])
title('a simple sine wave')
xlabel('Time (seconds)');
ylabel('Amplitude');
% sound(mysig); %You can play the sound if you like!
%-------------------------------------------------------------------------------------

Creating a complex wave

Add some sine waves together, with different frequencies and phases. The next program is based on make_sin, but adds together waves of different frequency and phase.

%-----------------------------------------------------------------------
% create_complex.m
%-----------------------------------------------------------------------
D = 1.2; %signal duration
S = 1000; % sampling rate, i.e. N points pt sec used to represent sine wave
F = [30 40 100 200]; % 4 frequencies in Hz
w = 2*pi*F; % convert frequencies to radians
P = [0 .5 .25 .3]; % 4 corresponding phases
A = [1 .5 .3 .2]; % corresponding amplitudes
T = 1/S; % sampling period, i.e. for this e.g. points at 1 ms intervals
t = [T:T:D]; % time vector %NB this has been corrected from previous version
mysig=zeros(1,length(t)); %initialise mysig
myphi=2*pi*P; % compute phase angle
nfreqs=length(F); % N frequencies in the complex
% Add all sine waves together to give composite
for thisfreq=1:nfreqs
mysig = mysig+A(thisfreq)*(sin(w(thisfreq)*t + myphi(thisfreq)));
end
figure; plot(t,mysig);
ylim([-2,2])
xlim([0,2])
title('a complex wave')
xlabel('Time (seconds)');
ylabel('Amplitude');
%-----------------------------------------------------------------------

If you don't understand about sampling rate, frequency or phase, experiment with altering values of S, F and P to see the effect on the wave. Hint: it is easiest to see how changing phase alters the signal if you select a frequency less than 10. Note that if you select a value of S that is less than twice F, the waveform changes, because the sampling is too slow to capture the fluctuations. 2*F is known as the Nyquist frequency, which is the lowest sampling frequency that can be used to correctly identify a sine wave of frequency F.

原文