normalize the frequency from 0 to 2pi in matlab

To normalize the frequency of a signal from 0 to 2pi in Matlab, you can use the unwrap and angle functions. Here is an example:

main.m
% Generate a sample signal
Fs = 1000; % Sampling frequency
f = 50; % Signal frequency
t = 0:1/Fs:1-1/Fs; % Time vector
x = sin(2*pi*f*t); % Sample signal

% Normalize frequency to 0 to 2pi
x_norm = x ./ abs(x); % Normalize amplitude to +/- 1
phase = unwrap(angle(x_norm)); % Unwrap the phase angle 
freq_norm = phase ./ (2*pi); % Normalize phase to 0 to 1 (or 0 to 2pi)

% Plot original and normalized signals
subplot(2,1,1)
plot(t,x)
xlabel('Time (s)'); ylabel('Amplitude')
title('Original Signal')
subplot(2,1,2)
plot(freq_norm,x_norm)
xlabel('Normalized Frequency (cycles/sample)'); ylabel('Amplitude')
title('Normalized Signal')
ylim([-1.1 1.1])
650 chars
22 lines

In this example, we first generate a sample signal with a frequency of 50 Hz and a sampling frequency of 1000 Hz. We then normalize the amplitude of the signal to +/- 1 using the ./ operator. We then use the angle function to compute the phase angle of the signal at each time point. This phase angle is wrapped between -pi and pi, so we use the unwrap function to properly unwrap the phase angle. Finally, we divide the phase angle by 2*pi to normalize the frequency to the range of 0 to 1 (or 0 to 2pi). We plot both the original and normalized signals to verify the results.

gistlibby LogSnag