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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Syed Ghazi Sarwat
le 12 Oct 2020
Commenté : Syed Ghazi Sarwat
le 19 Oct 2020
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)
0 commentaires
Réponse acceptée
Mathieu NOE
le 12 Oct 2020
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;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spectral Estimation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!