Determine if the data contains a 50 Hz sine wave and if so, over what time period..

2 views (last 30 days)
Question: The file prob2_33_data.mat contains a signal x (fs = 500 Hz). Determine if this signal contains a 50-Hz sine wave and if so over what time periods. Do I determine it is a sone wave by finding the correlation coefficient?
Code + data:
% Problem2_33.mat
% Determine if this signal contains a 50-Hz sine wave and if so ...
% over what time periods.
clear all;
close all;
clc;
fs = 500; % Sample frequency
load prob2_33_data.mat; % get data of input signal from file
figure;
subplot(2,1,1);
plot(x); % Plot of input signal x(t)
xlabel('Time (sec)','FontSize',18);
ylabel('Signal (milli volts)','FontSize',18);
title('Random input signal x(t) ','FontSize',18);
grid on;
f = 50;
t = (1:fs/f)/fs; % Generate only 1 cycle
y = sin(2*pi*f*t); % Generate a sine wave
subplot(2,1,2);
plot(t,y); % Plot the 50Hz
xlabel('Time (sec)','FontSize',18);
ylabel('Signal (milli volts)','FontSize',18);
title('50 Hz signal y(t) ','FontSize',18);
grid on;
[rxy, lags] = crosscorr(x,y,'p'); % compute the cross correlation of the signal x and y
figure(2);
plot(lags,rxy); % Plot of auto corleation between 2 signal x and y
xlabel('Lags (n)','FontSize',14);
ylabel('r_x_y','FontSize',14);
title('Cross corelation between x(t), y(t) ','FontSize',18);
grid on;
[max_corr1, max_shift1] = max(rxy(1:1500)); % Plot show two possible peaks
figure(3);
plot( [max_corr1 max_shift1]);
[max_corr2, max_shift2] = max(rxy(1500:2500)); % Toward begining and middle of data
[max_corr3, max_shift3] = max(rxy(2500:4000)); % Plot show two possible peaks
Td1 = lags(max_shift1)/fs; % Time shift 1
Td2 = lags(max_shift2+1500)/fs; % Time shift 2
Td3 = lags(max_shift3+2500)/fs; % Time shift 3
disp('Max corr ');
disp([max_corr1 max_corr2 max_corr3 ]);
disp(' Times (sec)');
disp([ Td1 Td2 Td3]);
  1 Comment
dpb
dpb on 23 Feb 2023
What is the signature for the function <crosscorr>?
There is no named parameter 'p' and even if were, it would need a value to go along with it as the error message says...look at the examples for the function that illustrate using those.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 23 Feb 2023
Have you tried periodogram and spectrogram?
  2 Comments
dpb
dpb on 24 Feb 2023
As it is homework, will leave specific code to the student; I'd venture there's a section towards the beginning of the signal that has a decent 50 Hz energy content, but beyond that, there's not a lot too choose...some content but nothing very dominant...

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!