필터 지우기
필터 지우기

My computer won't run a code with bandpass filter

조회 수: 1 (최근 30일)
Michele Woodland
Michele Woodland 2020년 5월 15일
댓글: Mathieu NOE 2020년 11월 30일
Hi everyone, I'm having trouble running a code that involves passing a signal through a bandpass filter. The exact same code runs on someone else's computer, so we are not sure why it won't run properly on mine. Here is the code.
%-1.599 bias
clc;
close all;
clear all;
Fs = 125e3; % Sample Frequency in Hz
fnyquist = Fs/2; %nyquist frequency
signal_with_bias = csvread('BallSignal.csv',1,0);
sig_i = signal_with_bias(:,1); %in_phase signal
sig_i = sig_i - mean(sig_i); %remove bias
sig_q = signal_with_bias(:,2);%quad_signal
sig_q = sig_q - mean(sig_q); %remove bias
signal = complex(sig_i, sig_q); %the complex signal
%Calculate DC bias
bias_i = mean(signal_with_bias(:,1));
fprintf('%f\n', bias_i)
bias_q = mean(signal_with_bias(:,2));
fprintf('%f\n', bias_q)
N =length(signal); %length of signal
t = (0:1:N-1)/Fs; %time period
Ts = mean(diff(t)); %sampling Time
fs =(0:N-1).*(Fs/N); %frequency vector
Is = 1:length(fs); % Index Vector
w = hann(N); %hanning window
ff=fft((signal .*w)); %fourier transform of the signal after hanning window
power = abs(ff).^2/N;
%b_signal = bandpass(ff, [2.35e4, 2.45e4],Fs); % apply a bandpass filter 23500Hz to 24500Hz
b_signal = bandpass(signal, [2.399e4, 2.405e4],Fs); % apply a bandpass filter 23500Hz to 41000Hz
fff =fft(b_signal.*w);
b_power = abs(fff).^2/N;
sig_f = ifft(fff); % inverse fourier transform of the filtered signal
%Plot Complex Signal
figure(1)
plot(t,real(signal .*w),'r',t,imag(signal .*w),'k');
title('Signal'); xlabel('time(s)'); ylabel('Voltage(V)');
legend('real', 'imaginary');
%Plot the Power Spectrum
figure(2)
plot(fs, power); %Frequency Vs. Power
title('Power Spectrum'); xlabel('Frequency(Hz)'); ylabel('Magnitude');
norm_ff = fft(signal)/N;
amp_fts = abs(norm_ff(Is))*2; % Spectrum Amplitude
phs_fts = angle(norm_ff(Is)); % Spectrum Phase
phase=atan2(imag(signal),real(signal))*180/pi; %phase information
%Power Spectrum after bandpass filter
figure(3)
plot(fs, b_power);
title('Power Spectrum of bandpass signal'); xlabel('Frequency(Hz)'); ylabel('Magnitude');
xlim([0,8e4]);
%Plot Bandpass Signal
figure(4)
plot(t,real(sig_f), 'r', t, imag(sig_f), 'k'); % plot the real and imaginary bandpass signal
title('Bandpass signal'); xlabel('time(s)'); ylabel('Voltage');
legend('real', 'imaginary');
I've attached the error I get. I tried running another code from mathworks' website and got a similar error. I have the signal processing toolbox and other codes using the toolbox work properly as long as a bandpass filter is not used. Is there something else I need to download? Any help is much appreciated.
  댓글 수: 5
Michele Woodland
Michele Woodland 2020년 5월 15일
I've attached the file (I changed the file to BackandForthMovement). The two columns are actually the in-phase and quadrature data. I will do that, thank you.
Mathieu NOE
Mathieu NOE 2020년 11월 30일
hello
late input from me
just in case it might help you in the future, this code is about the standard digital filters used in audio
maybe sometimes the good old fashioned way can help

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by