Hi I have a query I removed the harmonic to preserve the fundamental but still fundamental at 1MHz is also filtered can anyone tell m e.
% Load the frequency domain data
folder = ‘C:UsershaneuOneDrive바탕 화면dateNew folder (2)’;
filename = ‘270mvp.csv’;
data = readtable(fullfile(folder, filename));
% Extract frequency and FFT amplitude (assumed to be in dB)
f = table2array(data(3:end, 3)); % Frequency data (in Hz)
x_dB = table2array(data(3:end, 4)); % FFT amplitude data in dB
% Number of points in the FFT
N = length(x_dB);
% Compute the sampling frequency (fs)
% Assuming that your frequency axis (f) is spaced evenly
df = f(2) – f(1); % Frequency resolution
fs = N * df; % Sampling frequency
% Convert the amplitude from dB to linear scale
x_linear = 10.^(x_dB / 20);
% Compute the Power Spectral Density (PSD)
pxx = (x_linear.^2) / (fs * N);
% Convert PSD to dB/Hz
pxx_dBHz = 10 * log10(pxx);
% Fundamental frequency
f0 = 1e6; % 1 MHz
% Identify harmonic frequencies
harmonics = f0 * (1:floor(max(f)/f0));
% Remove harmonics from PSD
pxx_dBHz_filtered = pxx_dBHz; % Copy original PSD
for k = 1:length(harmonics)
harmonic_freq = harmonics(k);
[~, idx] = min(abs(f – harmonic_freq)); % Find the closest frequency index
pxx_dBHz_filtered(idx) = -Inf; % Set PSD of harmonics to -Inf (effectively removing)
end
% Plot the original Power Spectral Density (PSD)
figure;
subplot(2, 1, 1);
plot(f/1e6, pxx_dBHz);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Original Power Spectral Density (PSD)’);
% Plot the filtered Power Spectral Density (PSD)
subplot(2, 1, 2);
plot(f/1e6, pxx_dBHz_filtered);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Filtered Power Spectral Density (PSD)’);
% Highlight fundamental frequency in the plot
hold on;
plot(f0/1e6, pxx_dBHz_filtered(abs(f – f0) < df), ‘ro’, ‘MarkerSize’, 8, ‘LineWidth’, 2);
legend(‘Filtered PSD’, ‘Fundamental Frequency’);% Load the frequency domain data
folder = ‘C:UsershaneuOneDrive바탕 화면dateNew folder (2)’;
filename = ‘270mvp.csv’;
data = readtable(fullfile(folder, filename));
% Extract frequency and FFT amplitude (assumed to be in dB)
f = table2array(data(3:end, 3)); % Frequency data (in Hz)
x_dB = table2array(data(3:end, 4)); % FFT amplitude data in dB
% Number of points in the FFT
N = length(x_dB);
% Compute the sampling frequency (fs)
% Assuming that your frequency axis (f) is spaced evenly
df = f(2) – f(1); % Frequency resolution
fs = N * df; % Sampling frequency
% Convert the amplitude from dB to linear scale
x_linear = 10.^(x_dB / 20);
% Compute the Power Spectral Density (PSD)
pxx = (x_linear.^2) / (fs * N);
% Convert PSD to dB/Hz
pxx_dBHz = 10 * log10(pxx);
% Fundamental frequency
f0 = 1e6; % 1 MHz
% Identify harmonic frequencies
harmonics = f0 * (1:floor(max(f)/f0));
% Remove harmonics from PSD
pxx_dBHz_filtered = pxx_dBHz; % Copy original PSD
for k = 1:length(harmonics)
harmonic_freq = harmonics(k);
[~, idx] = min(abs(f – harmonic_freq)); % Find the closest frequency index
pxx_dBHz_filtered(idx) = -Inf; % Set PSD of harmonics to -Inf (effectively removing)
end
% Plot the original Power Spectral Density (PSD)
figure;
subplot(2, 1, 1);
plot(f/1e6, pxx_dBHz);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Original Power Spectral Density (PSD)’);
% Plot the filtered Power Spectral Density (PSD)
subplot(2, 1, 2);
plot(f/1e6, pxx_dBHz_filtered);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Filtered Power Spectral Density (PSD)’);
% Highlight fundamental frequency in the plot
hold on;
plot(f0/1e6, pxx_dBHz_filtered(abs(f – f0) < df), ‘ro’, ‘MarkerSize’, 8, ‘LineWidth’, 2);
legend(‘Filtered PSD’, ‘Fundamental Frequency’); % Load the frequency domain data
folder = ‘C:UsershaneuOneDrive바탕 화면dateNew folder (2)’;
filename = ‘270mvp.csv’;
data = readtable(fullfile(folder, filename));
% Extract frequency and FFT amplitude (assumed to be in dB)
f = table2array(data(3:end, 3)); % Frequency data (in Hz)
x_dB = table2array(data(3:end, 4)); % FFT amplitude data in dB
% Number of points in the FFT
N = length(x_dB);
% Compute the sampling frequency (fs)
% Assuming that your frequency axis (f) is spaced evenly
df = f(2) – f(1); % Frequency resolution
fs = N * df; % Sampling frequency
% Convert the amplitude from dB to linear scale
x_linear = 10.^(x_dB / 20);
% Compute the Power Spectral Density (PSD)
pxx = (x_linear.^2) / (fs * N);
% Convert PSD to dB/Hz
pxx_dBHz = 10 * log10(pxx);
% Fundamental frequency
f0 = 1e6; % 1 MHz
% Identify harmonic frequencies
harmonics = f0 * (1:floor(max(f)/f0));
% Remove harmonics from PSD
pxx_dBHz_filtered = pxx_dBHz; % Copy original PSD
for k = 1:length(harmonics)
harmonic_freq = harmonics(k);
[~, idx] = min(abs(f – harmonic_freq)); % Find the closest frequency index
pxx_dBHz_filtered(idx) = -Inf; % Set PSD of harmonics to -Inf (effectively removing)
end
% Plot the original Power Spectral Density (PSD)
figure;
subplot(2, 1, 1);
plot(f/1e6, pxx_dBHz);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Original Power Spectral Density (PSD)’);
% Plot the filtered Power Spectral Density (PSD)
subplot(2, 1, 2);
plot(f/1e6, pxx_dBHz_filtered);
xlabel(‘Frequency (MHz)’);
ylabel(‘PSD (dB/Hz)’);
title(‘Filtered Power Spectral Density (PSD)’);
% Highlight fundamental frequency in the plot
hold on;
plot(f0/1e6, pxx_dBHz_filtered(abs(f – f0) < df), ‘ro’, ‘MarkerSize’, 8, ‘LineWidth’, 2);
legend(‘Filtered PSD’, ‘Fundamental Frequency’); signal processing, filter MATLAB Answers — New Questions