希尔伯特变换matlab代码
时间: 2023-07-31 07:07:00 浏览: 84
Sure! Here is an example of a MATLAB code for performing the Hilbert transform:
```matlab
% Input signal
t = 0:0.01:2*pi;
x = sin(t);
% Perform Hilbert transform
y = hilbert(x);
% Plot the original and transformed signals
subplot(2,1,1);
plot(t, real(x), 'b', t, imag(x), 'r--');
xlabel('Time');
ylabel('Amplitude');
title('Original Signal and its Hilbert Transform');
legend('Real part', 'Imaginary part');
subplot(2,1,2);
plot(t, real(y), 'b', t, imag(y), 'r--');
xlabel('Time');
ylabel('Amplitude');
legend('Real part', 'Imaginary part');
% Calculate instantaneous phase and frequency
inst_phase = unwrap(angle(y));
inst_freq = diff(inst_phase) / (2*pi);
% Plot the instantaneous phase and frequency
figure;
subplot(2,1,1);
plot(t(1:end-1), inst_phase, 'b');
xlabel('Time');
ylabel('Phase');
title('Instantaneous Phase');
subplot(2,1,2);
plot(t(1:end-1), inst_freq, 'r');
xlabel('Time');
ylabel('Frequency');
title('Instantaneous Frequency');
```
This code generates a sinusoidal signal and then performs the Hilbert transform using the `hilbert` function in MATLAB. It plots both the original signal and its Hilbert transform in the time domain. It also calculates the instantaneous phase and frequency from the Hilbert transform and plots them separately.
Please note that this is just a basic example, and you may need to modify it according to your specific requirements.