I am generating a sine wave with a phase difference. The peak amplitude however seems to scale with the phase difference, which should not be case. Any suggestions to where this code is going wrong ?

9 次查看(过去 30 天)
Frequency = 15 ; % in Hertz
SamplingFrequency = 100*Frequency; % in Hertz. Note: Increasing the sampling frequency does not help.
Simulationtimestep = 1/SamplingFrequency; % Simulation time-step
Simulationtime=0:Simulationtimestep:1-Simulationtimestep; % Simulation time
Phasediff = deg2rad(20); % in radians
Amplitude = 2;
Wave1 = Amplitude*sin(2*pi*Frequency*Simulationtime); % Reference Wave
Wave2 = Amplitude*sin(2*pi*Frequency*Simulationtime+Phasediff ); % Wave with phase difference
disp(max(Wave1));%Should be equal to 2
Wave1Peaks = numel(find(Wave1==Amplitude)); % Should be equal to the frequency (15)
disp(max(Wave2)); %Should be equal to 2
Wave2Peaks = numel(find(Wave2==Amplitude)); % Should be equal to the frequency (15)

采纳的回答

Mathieu NOE
Mathieu NOE 2020-10-12
hi
problem solved - see below
I also increased your sampling frequency (360 x 15 Hz) so that you get the best results accuracy for 1° changes in your phase diff value.
clc
Frequency = 15 ; % in Hertz
SamplingFrequency = 360*Frequency; % in Hertz. Note: Increasing the sampling frequency does not help.
Simulationtimestep = 1/SamplingFrequency; % Simulation time-step
Simulationtime=0:Simulationtimestep:1-Simulationtimestep; % Simulation time
Phasediff = pi/180*(22); % in radians
Amplitude = 2;
Wave1 = Amplitude*sin(2*pi*Frequency*Simulationtime); % Reference Wave
Wave2 = Amplitude*sin(2*pi*Frequency*Simulationtime+Phasediff ); % Wave with phase difference
disp(max(Wave1));%Should be equal to 2
Wave1Peaks = numel(find(Wave1==Amplitude)); % Should be equal to the frequency (15)
disp(max(Wave2)); %Should be equal to 2
Wave2Peaks = numel(find(Wave2==Amplitude)); % Should be equal to the frequency (15)
% example of findpeaks usage for Wave1
Wave1Peaks_ind = findpeaks(Wave1); % indexes of peak values
Wave1Peaks_Time = Simulationtime(Wave1Peaks_ind)
Wave1Peaks_Amplitude = Wave1(Wave1Peaks_ind)
% example of findpeaks usage for Wave2
Wave2Peaks_ind = findpeaks(Wave2); % indexes of peak values
Wave2Peaks_Time = Simulationtime(Wave2Peaks_ind)
Wave2Peaks_Amplitude = Wave2(Wave2Peaks_ind)
function n = findpeaks(x)
% Find peaks.
% n = findpeaks(x)
n = find(diff(diff(x) > 0) < 0);
u = find(x(n+1) > x(n));
n(u) = n(u)+1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Estimation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by