My computer won't run a code with bandpass filter
Afficher commentaires plus anciens
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 commentaires
Star Strider
le 15 Mai 2020
What MATLAB version/release do you have?
What MATLAB version/release does someone else’s computer have?
The bandpass function was introduced in R2018a.
Bandpass (and other) filters are relatively straightforward to design using command line functions.
Michele Woodland
le 15 Mai 2020
Star Strider
le 15 Mai 2020
I don’t have ‘BallSignal.csv’ so I can’t run your code to see if I can figure out if the problem may have something to do with that file (although I doubt it’s the problem).
When I substitute:
signal_with_bias = [linspace(0, 1, 100).', rand(100, 1)+10];
(asssuming the the first column is supposed to be time and the second the signal), without any other changes, the code runs correctlly with no errors. The narrowband bandpass filter also appears to work correctly.
It might be best for you to use the Contact Us telephone handset icon in the upper-right corenr of this page to request Technical Support. Include the URL of this thread so you don’t have to repeat everything, and so Technical Support knows what you’ve already tried.
Michele Woodland
le 15 Mai 2020
Mathieu NOE
le 30 Nov 2020
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
Réponses (0)
Catégories
En savoir plus sur Pulse and Transition Metrics dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!